Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mulit-Language Site - best practices?

Status
Not open for further replies.

Geee

Programmer
Apr 23, 2001
253
GB
Hello,

I have created a full e-comm site which uses multi-language fields in the database to allow all of the products to be displayed in 1 of 5 languages. This is no problem and completed. However, for the static pages, page titles etc I need to store the copy in 5 languages. I am currently doing this using flat file xml files and pulling the xml into an array then displaying the correct element depending on the language, eg:

Code:
<xml>
<title_en>English Title</title_en>
<title_fr>French Title</title_fr>
<title_de>German Title</title_de>
...
</xml>

Then displaying like so:

Code:
<h1><?php echo $xml['title_'.$_SESSION['lang']]; ?></h1>

Now this all works fine and dandy, my question is; is this a viable scalable way of solving this problem? Obviously there are a million other ways to do the same thing, but I'm concerned about getting this right with regards to scalability and performance. The model has been simplified somewhat for display here before anyone criticises my xml or code techniques!

-Geeeeeeeeeeeeeeeeeeeeeeee-
-=
 
I don't know how it compares, but a method that I see often and have occasionally used is to have separate language files, like en.php, de.php, es.php, etc., or files in language directories, like /lang/en/menu.php, lang/en/help.php.

Then each file contains variables which contain strings, like so:

<?php
// English messages file
$msg_noaccess = "Access Denied";
$msg_granted = "Access Granted";
...
?>

Finally, the executed page would contain lines like this:

require_once("/lang/".$_SESSION['lang']."/messages.php");
echo $msg_noaccess;


If the messages are split up somewhat it might scale better, especially if separate directories are used, as all languages or strings wouldn't need to be included by every file.
 
I was doing something similar using a language map database table
[tt]
+--------+-----+---+---+
|stringID|en |ch |jp |
+--------+-----+---+---+
|00001 |hello|xxx|xxx|
|00002 |bye |xxx|xxx|
|00003 |offer|xxx|xxx|
[/tt]
etc. My pages don't have any static text string. Depending on the strings and language that I need on a particular page, I would use a select statement to retrieve them and put them in an array for use. The upside is that you only need to manage one set of pages and can add as many languages as you like. The down side is that I always forget what the string ID is and need to have a hard copy of the language map on hand.


--== Anything can go wrong. It's just a matter of how far wrong it will go till people think its right. ==--
 
In many projects gettext is used. Based on a php-file with gettext or _ in it, gettext generates a list of words that needs to be translated.
When translated, put the files in de correct folders and set the language via setlocale(LC_MESSAGES, 'en_GB') to the correct language. When no translation can be found the text from the sourcefile will be used.

Hope this helps.
PS access to commandline is needed for this. Refer to gettext (man gettext) to learn more.

mcvdmvs
&quot;It never hurts to help&quot; -- Eek the Cat
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top