468,783 Members | 1,640 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,783 developers. It's quick & easy.

Multi-language & global variables

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
2 2911
"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
"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.

Similar topics

4 posts views Thread by Frank Jona | last post: by
5 posts views Thread by bobwansink | last post: by
reply views Thread by zhoujie | last post: by
2 posts views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.