Hi,
I could need some advice. In my script I'm reading a language translation file (some hundred entries). which file I select depends on the user selections (i.e. $_GET['lang']). my problem is currently, how to decide which file to load. additionally, if there's ever a new file added (or changed), I don't want the user to have to dig through a lot of code to get it working.
way 1: make a configuration file, which lists which values (the short language names like de, en, …) map to which file.
Drawback: I need an additional config file/the config file must be updated
way 2: the language files contain a value of the appropriate abbreviation so I could read that value and decide, if I use this file or not.
Drawback: in the worst case I have to parse all files, before I get the right one.
way 3: I could think of some code using fread() or file() and stop after the "lang_short " line.
any ideas what the best/most elegant way is?
thanks
I could need some advice. In my script I'm reading a language translation file (some hundred entries). which file I select depends on the user selections (i.e. $_GET['lang']). my problem is currently, how to decide which file to load. additionally, if there's ever a new file added (or changed), I don't want the user to have to dig through a lot of code to get it working.
way 1: make a configuration file, which lists which values (the short language names like de, en, …) map to which file.
Code:
$map = parse_ini_file(config.lang.ini);
/* giving:
$map = array
(
"en" => "English.ini",
"de" => "German.ini",
…
); */
$translation = parse_ini_file($map[$language]);
way 2: the language files contain a value of the appropriate abbreviation so I could read that value and decide, if I use this file or not.
Code:
// English.ini
; some preceding lines
; of comment
…
lang_short = "en"
…
// PHP
foreach ($files_from_readdir as $ini_file)
{
$file = parse_ini_file($ini_file);
if ($file['short_lang'] == $language)
{
$translation = $file;
break;
}
}
way 3: I could think of some code using fread() or file() and stop after the "lang_short " line.
any ideas what the best/most elegant way is?
thanks
Comment