I'm supposed to do a big portal with multi-language support and I'm
decided to do my own instead of going for gettext. I have sort out few
implementations; most of them uses global variables. I'm bit confused,
how it will affect the performance. Right now, I use global variables
in config file. Most of the experts in this group are ranting against
global variable usage. I would like to know how would you handle such
config settings (DB is not the right way, IMHO). Also, like to know,
how would you handle this multi-languge implementations. Suggestions
and comments are highly appreciated. TIA.
1. Language support in single file with hash array. All variables are
global.
<?php
//languages.php
$lang['en']['hello'] = 'Hello';
$lang['fr']['hello'] = 'French hello';
$lang['en']['logout'] = 'Log out';
$lang['fr']['logout'] = 'French Logout';
//..
?>
2. Individual files for each language. A particular languge file is
included. But, each language has only one include file. All variables
are global.
<?php
//language.en.php
$hello = 'Hello'; // or $lang['hello'] = 'Hello';
$logout = 'Logout'; // or $lang['logout'] = 'Logout';
//..
?>
<?php
//language.fr.php
$hello = 'French Hello'; // or $lang['hello'] = 'French Hello';
$logout = 'French Logout'; // or $lang['logout'] = 'French Logout';
//..
?>
3. OsCommerce like implementation. Each language file for each
languages. But, each file has it's own language file. For example,
singup.php will have it's own English & French files that will be
included. This seems to increase performance 'coz only few variables
will be loaded. All variables are defined (but don't know the _real_
difference between define & global.
4. A function with full of private variables.
<?php
//lang_func.php
function getTranslation($lng, $text)
{
$lang['en']['hello'] = 'Hello';
$lang['fr']['hello'] = 'French hello';
$lang['en']['logout'] = 'Log out';
$lang['fr']['logout'] = 'French Logout';
//..
return( $lang[$lng][$text] );
}
?>
5. Using DB is another way. But, we don't want to go for DB.
Any other suggestions or improvments??
--
http://www.sendmetoindia.com - Send Me to India!
Email: rrjanbiah-at-Y!com