Log in

View Full Version : Translation



glucarelli
02-17-2007, 01:43 PM
I have this piece of code


<? echo" $curr_text"; ?>

The value of $curr_text is in english and i would like to translate it in french
example :
if $curr_text=Most then the value displayed is Plus
if $curr_text=Often then the value displayed is Souvent
continuing with other words
How could i write those conditions ?
Any advice would be helpfull
Thanks

mburt
02-17-2007, 01:46 PM
The two word lists can be stored in arrays:

<?php
$english = array("Most","Often");
$french = array("Plus","Souvent");
$cur_text = "Most";
for ($i = 0;$i < count($english);$i++) {
if ($cur_text == $english[$i]) {
echo $french[$i];
}
}
?>
Note: they must be in corresponding order.

Twey
02-17-2007, 03:13 PM
The common approach is to store all the translations in a big array:
$LANG = array(
'en' => array(
'l_most' => 'most',
'l_often' => 'often'
),
'es' => array(
'l_most' => 'm&#225;s',
'l_often' => 'a menudo'
),
'fr' => array(
'l_most' => 'plus',
'l_often' => 'souvent'
)
);Store it in an external file, include it into every page, then
echo $LANG[$_SESSION['pref_lang']]['l_most']where $_SESSION['pref_lang'] is the name of the language. However, beware of differing word order, especially if dealing with non-Romance languages. For this reason, every site I've ever seen translate things by the sentence rather than by the word.

mburt
02-17-2007, 03:16 PM
Or just store like this in a file:

segment 1|two|three|etc.

and use explode() for the array. I use that for my menus and lists on my site, it keeps things organized. Same method, different approach.