@pradeepjain
I'm actually working on making a site multi-lingual now, in fact, so we have some common ground there.
Anyway, what I did was (after seeing Dorm do the same), create .ini language files that contain key => value pairs, that I could parse into an array using PHP's parse_ini_file() function. The lang files looked like this, note that the key has punctuation stripped (apart from hypens):
lang.en.ini
-
hello = "Hello"
-
goodbye = "Goodbye"
-
today = "Today"
-
All of your .ini files would share the same set of keys, where the value changes to the language in question. So the French language would look like this:
lang.fr.ini
-
hello = "Bonjour"
-
goodbye = "Au revoir"
-
today = "Aujourd'hui"
-
I then wrote a Language class that would produce an object with methods for retrieving values from the language array, parsing a new language array (parse_ini_file()), and others. The basic structure of that class:
-
<?php
-
-
class My_Lang {
-
-
/**
-
* Some doc
-
*/
-
private $langs = array();
-
/**
-
* Some doc
-
*/
-
private $dict = array();
-
-
public function __construct($lang = null) {
-
// Load a default language
-
if (!$lang) {
-
$this->lang = 'en';
-
} else {
-
$this->lang = $lang;
-
}
-
-
$this->loadLangs();
-
$this->loadLang($this->lang);
-
}
-
-
/**
-
* Loads all available language selectors from
-
* some specified lang dir, into our
-
* $langs array.
-
*
-
* @return bool
-
*/
-
public function loadLangs() {
-
// Load language selectors
-
$this->langs = $availLangsArray;
-
}
-
-
/**
-
* Loads language array into our $dict array
-
*
-
* @return bool
-
*/
-
public function loadLang($lang) {
-
// Must be available to load
-
if (!in_array($lang, $this->langs)) {
-
throw new My_Lang_Not_Available;
-
}
-
-
$this->dict = parse_ini_file('/path/to/'. $lang. '.ini');
-
}
-
-
}
-