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

    Join Date
    Dec 2012
    Rep Power

    Using variables to hold site content for internationalization


    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:


    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.

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

    Join Date
    Mar 2007
    Washington, USA
    Rep Power
    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
    Rep Power

    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:
    {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
    Seattle, U.S.A.
    Rep Power
    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:

    [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