Changing to UTF-8

From TNG_Wiki
Revision as of 15:02, 18 June 2008 by KenRoy (talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Notes on changing a TNG Site and database to UTF-8


1 - Use phpMyAdmin to make a copy of your database (always make a copy in case something goes wrong!!!!!!!)

1.1 - In the databases list on the left click on the Database to select it.

1.2 - On the right side click on the Operations Tab. In the section called "Copy Database to" enter a name for your new database, and make sure that "Structure and Database" and "CREATE DATABASE before copying" are both checked, then click "Go".

When done this will have created a copy of your database.


2 - You need to run a script to change the structure of your database to UTF-8

2.1 - download the script from

http://www.phoca.cz/articles/web/how-to-change-collation-in-database/

and put it into your site's folder, then load the page to your site.

http://URLToYourSite/tool_phoca_changing_collation/

2.2 - Fill out the 5 boxes with the values needed for your site including choosing a collation of the form

utf8_xxxxxx_ci

xxxxxx is whatever you choose to use as your utf8 collation - eg swedish, general, unicode etc. The collation affects how characters are sorted, eg does ø sort with o or come at the end of the alphabet? Does å sort with a or come at the end of the alphabet? Does ß sort with s or with ss? etc. This page

http://dev.mysql.com/doc/refman/5.0/en/charset-unicode-sets.html

has some information about how some characters are handled in different collations. Choose the collation based on the principal language that your site is about.

Once you've decided on what collation you want to use and entered it into the 5th box, click the Submit button. This will convert the database, tables and columns to the collation you've chosen. The progress will be shown as it goes along. The last tables altered are tng_xnotes, so if you don't see these as the last items listed in the output the script didn't complete.

2.3 - when this has completed (on a large database it can take some time) a message appears at the bottom of the page with a link back to the Home Page. Until this link appears the script hasn't completed.


3 - edit the tng_db_connect function in globallib.php to get the queries performed in UTF-8. Otherwise even though the data is now stored in the database as UTF-8 it's not being retrieved properly by the queries

NOTE THIS STEP ISN'T REQUIRED FOR TNG 7

3.1 - Change line 52 of globallib.php to be

global $textpart, $session_charset;


3.2 - Add these two lines

if ($session_charset == 'UTF-8')
@mysql_query("SET NAMES 'utf8'");


after line 53 so that the whole function becomes


function tng_db_connect($dbhost,$dbname,$dbusername,$dbpassword) {
global $textpart, $session_charset;
$link = @mysql_connect($dbhost, $dbusername, $dbpassword);
if ($session_charset == 'UTF-8')
@mysql_query("SET NAMES 'utf8'");
if( $link && mysql_select_db($dbname))
return $link;
else if( $textpart != "setup" && $textpart != "index" ) {
echo "Error: TNG is not communicating with your database. Please check your database settings and try again.";
exit;
}
return( FALSE );
}


4 Change the settings that TNG is using for Character Set.

4.1 - In the TNG Admin ------> Setup ------> General Settings ------> Language change the Character Set to "UTF-8" (without the "" marks) and save the changes.

4.2 - Do the same in TNG Admin ------> Languages ------> each language you support to change them to UTF-8


5 - Change the encoding in the text files for each language that you support.

5.1 - Here's what works on Macintosh. You need TextWrangler - a free text editor. If you don't already have TextWrangler, or its big brother BBEdit, you can download the free TextWrangler from

http://www.barebones.com/products/textwrangler/

5.1.1 - For each language folder open the files admintext.php, alltext.php, text.php and cust_text.php in TextWrangler

5.1.2 - For each file after it is open, go to the File menu and choose "Reopen using Encoding ------> Western (Windows Latin 1).

5.1.3 - At the bottom of the TextWrangler window is a pop up menu should now say "Western (Windows Latin 1)". Click on this and choose "Unicode™ (UTF-8, no BOM)"

5.1.4 - Save the file.

5.1.5 - repeat for the other files for each of your languages.

That's it. Your site should now be running in UTF-8.