Hi all,

Just need some direction on this:

I need to start applying and developing applications in French and English. What i mean is the GUIs that i develop need to translate to French or English not translating word for word just the complete text. For example "Part Number" would be translated as a whole phrase not separate translations for each word.
So what i need to do is have some sort of language lookup by detecting the users locale and then applying the appropiate language.

I am open to suggestions on the "best" way to do this. My first thoughts are database, having a base phrase and then a French translation. The only downside to this i guess is round trips to the db everytime a page is loaded.

My next thought was using xml. Storing paired values and outputting.

The last thought was some type of .properties file that also had a base value in english and then an equivilant French translation.

I dont want to use any automatic translaters and certainly dont want to create separate language pages.

So has anyone done this, what have they used or has anyone seen any methods on the internoodle.

Thanks

Matt

I have done this before using what i have called a "language pack" file. It as a ".lng" files that sits in my /languages directory having identifiable file names (en, fr, it, etc...) and would be included based on the user's choice.

For example, the fr.lng.php file contained a big array of the English words (sentence) as the key, and the French translation as the value:

$lng = array(
"Welcome" => "Acceuil",
"student status" => "statut de l'étudiant",
"library" => "bibliothèque"
);

While the en.lng.php would have:

$lng = array(
"Welcome" => "Welcome",
"student status" => "student status",
"library" => "library"
);

I later realized that I could've simply printed the array key name instead of creating a whole file for the English language.

Of course, simple include the language pack after getting it from the user and setting the language in, say, the variable $lang:

include_once("languages/$lang.lng.php");

and then call the array whenever you have something to translate:

...
echo "<div class=\"somestyle\">".$lng["Welcome"]."</div>";
...

This might not be the best approach, but it is by all means the fastest. And it worked like charm. IMHO, XML would be too much hassle.

This article has been dead for over six months. Start a new discussion instead.