By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,199 Members | 1,440 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,199 IT Pros & Developers. It's quick & easy.

Multi-language & global variables

P: n/a
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
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"R. Rajesh Jeba Anbiah" <ng**********@rediffmail.com> wrote in message
news:ab**************************@posting.google.c om...
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.


That's probably the most flexible solution, since it allows you to customize
for each language. What you can do is automate the process of building the
PHP files, using some kind of a template system, so that you don't have a
dozen versions of essentially the same files.
Jul 17 '05 #2

P: n/a
"Chung Leong" <ch***********@hotmail.com> wrote in message news:<Qo********************@comcast.com>...
"R. Rajesh Jeba Anbiah" <ng**********@rediffmail.com> wrote in message
news:ab**************************@posting.google.c om...
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.


That's probably the most flexible solution, since it allows you to customize
for each language. What you can do is automate the process of building the
PHP files, using some kind of a template system, so that you don't have a
dozen versions of essentially the same files.


Thanks for your comments. BTW, I'm still skeptical that such
implementation might have some better-elegant solutions.

--
http://www.sendmetoindia.com - Send Me to India!
Email: rrjanbiah-at-Y!com
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.