Multi-language & global variables

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • R. Rajesh Jeba Anbiah

    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
  • Chung Leong

    #2
    Re: Multi-language &amp; global variables

    "R. Rajesh Jeba Anbiah" <ng4rrjanbiah@r ediffmail.com> wrote in message
    news:abc4d8b8.0 404012138.40881 f74@posting.goo gle.com...[color=blue]
    > 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.[/color]

    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.


    Comment

    • R. Rajesh Jeba Anbiah

      #3
      Re: Multi-language &amp; global variables

      "Chung Leong" <chernyshevsky@ hotmail.com> wrote in message news:<Qo-dnUmgDJNAYvDdRV n-sA@comcast.com> ...[color=blue]
      > "R. Rajesh Jeba Anbiah" <ng4rrjanbiah@r ediffmail.com> wrote in message
      > news:abc4d8b8.0 404012138.40881 f74@posting.goo gle.com...[color=green]
      > > 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.[/color]
      >
      > 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.[/color]

      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

      Comment

      Working...