7 Years
Discussion Span
Last Post by diafol

Try Google.


Well, depends if you're using client-side language or server-side language to implement the language interface. Server-side is 'easiest' in my opinion. I regularly develop bilingual and the odd multilingual sites.

You have a few options:

1. You can use a CMS like Joomla and implement Joomfish. It's a little awkward, but tends to be quite easy after the initial fiddle.
2. gettext - use po files - this is really awkward and I don't suggest this unless you know what you're doing.
3. language (array) files - probably the easiest DIY method. I find this easiest when using a template engine like RainTPL or Smarty.

A simple method:

in a folder called 'lang', have the individual language files of your choice:

en.php (English), cy.php (Welsh), it.php (Italian), etc etc

each will need to have an identical structure:

$lang = array(
 //meta and nav info
 "lang_name"   => "English",
 "meta_code"   => "en-GB",
 "lang_native" => "English",
 "lang_dir"    => "ltr",
 //login form
 "lbl_username"=> "Username:",
 "lbl_password"=> "Password:",

$lang = array(
 //meta and nav info
 "lang_name"   => "Welsh",
 "meta_code"   => "cy-GB",
 "lang_native" => "Cymraeg",
 "lang_dir"    => "ltr",
 //login form
 "lbl_username"=> "Defnyddiwr:",
 "lbl_password"=> "Cyfrinair:",


Get the idea?

Now you need a way of including the appropriate lang file into the page:

//get the current language from the $current_lang variable - set this in your config file - could be changed via $_GET or $_POST. I recommend $_GET - easier.

<html xmlns="http://www.w3.org/1999/xhtml" dir="<?php echo $lang['lang_dir'];?>" lang="<?php echo $meta_code;?>" xml:lang="<?php echo $lang['lang_dir'];?>">
 <meta name="language" content="<?php echo $lang_name;?>" />
 <meta http-equiv="Content-Language" content="<?php echo $meta_code;?>" />


<label for="username"><?php echo $lang['lbl_username'];?></label>

Notice how tedious the php echoes are: you can use a templating engine to make life easier.

If you're interested in this method, I can give you more examples, such as selecting a language / storing language choice, using RainTPL, etc.

Edited by diafol: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.