#1
  1. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2004
    Posts
    2,967
    Rep Power
    374

    Handling languages - suggestion please?


    How would/should I go about handling different languages? at the moment i do something like:

    // on the actual page
    $lang = "english";
    include_once ./path/to/languages/folder/$lang.php
    ...somewhere down the page:
    echo $lang[$lang]['hello'];


    $lang.php =

    $lang['english'] = array (
    'hello' => Hello
    )
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

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

    stuffing the translations into a PHP array and including it in the main script doesn't sound like a good idea. It requires you to constantly mess with the PHP source code, and if you (or anybody working on the translation) ever produce a syntax error, the whole application will uncontrollably crash. Personally, I also don't like the PHP syntax noise.

    I basically see two options:

    If you're the only one to work on the language entries, and if you rarely change them, put them into external JSON files (or any format you like, YAML, XML, whatever).

    If many (non-tech) people work on the entries, or if they're changed very often, consider putting them into the database and writing a simple GUI for editing.

    It might also make sense to cache the entries in case you experience performance issues.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2004
    Posts
    2,967
    Rep Power
    374
    didnt see the reply until now.

    Thanks for your suggestion. I was going to put them into a database but thought there would be too much of a headache in terms of php having to do more work and cause delays. (some of my script are already causing this issue ).

    how would I go about the option 1? would there be one XML per language or?

IMN logo majestic logo threadwatch logo seochat tools logo