translate to other language

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ahad_yekta2004
Forum Newbie
Posts: 6
Joined: Fri Jul 23, 2010 2:00 am

translate to other language

Post 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 .
klevis miho
Forum Contributor
Posts: 413
Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:

Re: translate to other language

Post by klevis miho »

You want a multilanguage page?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: translate to other language

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply