#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    1
    Rep Power
    0

    Using variables to hold site content for internationalization


    Hello,

    I have set up my database and application to handle UTF-8 data.

    I now would like to offer visitors a pulldown to choose which one of four languages they would like to view the site proper in. For example, if the Chinese language is chosen by a visitor, she would see all site content in Chinese (e.g., help, login page, etc.).

    To achieve this, I would like to use PHP associative arrays. For instance:

    $language['english']['help_text_05']
    $language['italian']['help_text_05']

    My concern is whether using this strategy would place a burden on the PHP server module. In total, I would have about 100,000 or so bytes (type string) of content stored in this array. Specifically, are their performance considerations involved that anyone can think of using this strategy as I layed it out?

    Thanks in advance.

    Mark
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,965
    Rep Power
    9397
    It's not worth holding all the data in memory at once when only one of the sets will be used.

    Store the data in separate locations so that the script(s) can get directly to the strings they want without having to get the other languages' too. As for whether arrays are the best solution, it depends on the site.
  4. #3
  5. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1046
    Hi,

    why would you load all texts of all languages into that array? Why not just load the texts you actually need for the current template and the current language?

    For example, the Smarty template engine supports configuration files, which can be used to make multi-language sites. On the top of each template, you'd load the corresponding section in the language file:
    Code:
    {config_load file="texts/languages/{$smarty.session.language}/general.conf" section="this_page"}
    (not sure if I got the syntax right, but I think you see what I mean)

    An even better solution would be to put a language stuff into the database.
  6. #4
  7. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2002
    Location
    Seattle, U.S.A.
    Posts
    712
    Rep Power
    12
    I don't think it'd be a problem with memory and I think is a valid way to store the language messages. Like others have said, I'd try and be smart about loading only the arrays you need, but I've seen applications like mediawiki (which powers Wikipedia) store their language messages in arrays that get loaded via a file:

    PHP Code:
    <?php

    $msg
    [lang'][en']['message-id'] = 'My Message';
    And then that file is included into your application as needed.

IMN logo majestic logo threadwatch logo seochat tools logo