Page 1 of 1

translate to other language

Posted: Wed Aug 04, 2010 9:38 am
by ahad_yekta2004
hi i wrote a page in php that have strings which should translate to other language in UTF-8 Unicode . i want to write translation in other page and load it in main page .

how to do it ? tell it by example if you can plz .

Re: translate to other language

Posted: Wed Aug 04, 2010 10:11 am
by klevis miho
You want a multilanguage page?

Re: translate to other language

Posted: Wed Aug 04, 2010 10:12 am
by pickle
Put the different strings to be translated in language-specific arrays, such as:

Code: Select all

<?PHP
$lang['en']['hello'] = 'Hello';
$lang['en']['person'] = 'person';

$lang['es']['hello'] = 'Hola';
$lang['es']['person'] = 'persona';

$lang['fr']['hello'] = 'Bonjour';
$lang['fr']['person'] = 'personne';?>
Build your page to include those language strings:

Code: Select all

<?PHP
$language = 'en';
?>
<html>
  <head>
    <title>
      <?php echo $lang[$language]['hello'].' '.$lang[$language]['person']; ?>
    </title>
    ...
Then, you can just change the $language variable to 'es' to change the page to Spanish, or 'fr' to change it to French.