SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 41
  1. #1
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Multi-Language Application Design

    How can i go about designing multi-language application?

    I want the application to be based on templates, for which i can do directory strcuture like
    template/en/templates

    But, how can i set up my application design to support multi-language error messages?


    even for templates, is my approach right??

    thanks
    ---------------------------
    Errors = Improved Programming.
    My Site

  2. #2
    SitePoint Member Sicloan's Avatar
    Join Date
    Nov 2005
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could do something like vbulletin does and use a Phrase system. in which you store all your phrases as $phrase['blah'] in your template system, and replace the phrases with the correct language

  3. #3
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So, storing ALL the error messages like that??
    ---------------------------
    Errors = Improved Programming.
    My Site

  4. #4
    SitePoint Addict
    Join Date
    Jan 2005
    Location
    United Kingdom
    Posts
    208
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jaswinder_rana
    So, storing ALL the error messages like that??
    At some point you will have to store all messages in all required languages somehow. Unless you want to look at translation services, which I think you probably don't

  5. #5
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    right, no i dont want "translation services". If users want they can translate on their own.

    also, do i put those messages in PHP file (in array) or in XML file?

    what might be advantage of one over another?
    ---------------------------
    Errors = Improved Programming.
    My Site

  6. #6
    SitePoint Guru BerislavLopac's Avatar
    Join Date
    Sep 2004
    Location
    Zagreb, Croatia
    Posts
    830
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jaswinder_rana
    do i put those messages in PHP file (in array) or in XML file?
    Here's a brief rundown of options you have:

    - PHP array in a separate file (include to use)
    - database table(s), including LDAP and similar
    - PHP ini file (farse_ini_file() to use)
    - XML file
    - another markup in a separate file: JSON, YAML, CSV...

    INI and CSV files have a tremendous advantage from a practical standpoint: you can give them to translators wou can open them and simpy edit them directly (INI in text editors, CSV in Excel, owned by most translators).

    Other than that, pick what suits you best.

  7. #7
    SitePoint Guru
    Join Date
    May 2005
    Location
    Finland
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by BerislavLopac
    INI and CSV files have a tremendous advantage from a practical standpoint: you can give them to translators wou can open them and simpy edit them directly
    You left out YAML.

    INI is well-suited for this task if you ask me. It supports up to two levels of depth (1. language, 2. the translated string - a perfect fit), is very readable and readily available in PHP.

  8. #8
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Ezku
    (1. language, 2. the translated string - a perfect fit), is very readable and readily available in PHP.
    what is the 2) part?? sorry, dint get it
    ---------------------------
    Errors = Improved Programming.
    My Site

  9. #9
    SitePoint Member
    Join Date
    Jan 2006
    Location
    Norway
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I recommend that you use getText, after all that's what it is made for.

    http://www.onlamp.com/pub/a/php/2002/06/13/php.html
    http://php.net/manual/en/ref.gettext.php

    Much easier than using arrays, ini or xml files.

    "All" you have to do is:
    PHP Code:
    <?php
    echo _('this is a text which will be translated if it is available in the requested local. If not use this string.');
    ?>

  10. #10
    SitePoint Wizard dreamscape's Avatar
    Join Date
    Aug 2005
    Posts
    1,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    INI style has sections and each section has "parameter = value" pairs. So for a language dictionary might look something like:
    Code:
    ; language dict
    [English]
    LoginError = No match for email and/or password.
    
    [German]
    LoginError = Keine Übereinstimmung für email und/oder Kennwort.
    
    [Spanish]
    LoginError = Ningún emparejamiento para el email y/o la palabra de paso.
    Obviously that is just a simple example, and I just used a translations service.

    Another way of doing the INI style would be giving each language its own or own set of INI files [such as english.ini, german.ini, spanish.ini] and separating the messages into groups, which become the sections, such as ErrorMessages, SucessMessages, etc...


    Don't forget about db translations either. If you have db content, you may want it in more than one language. How I usually do this would be a schema something like this for a simple article system for example [this could probably use some more thought as it is right off the top of my head]:
    Code:
    language
    -----------
    id (PK)
    name
    iso2
    iso3
    status
    date_added
    last_modified
    
    
    author
    -----------
    id (PK)
    name
    email
    status
    date_added
    last_modified
    
    
    article
    -----------
    id (PK)
    author_id (FK)
    sort_order
    status
    date_published
    date_added
    last_modified
    
    
    article_text
    -----------
    article_id (PK, FK)
    language_id (PK, FK)
    title
    summary
    text
    date_added
    last_modified

  11. #11
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Fjoggen
    I recommend that you use getText, after all that's what it is made for.

    http://www.onlamp.com/pub/a/php/2002/06/13/php.html
    http://php.net/manual/en/ref.gettext.php

    Much easier than using arrays, ini or xml files.

    "All" you have to do is:
    PHP Code:
    <?php
    echo _('this is a text which will be translated if it is available in the requested local. If not use this string.');
    ?>
    I fyou ahve used it, then does it translate properly?? i Mean all the letters and everything
    ---------------------------
    Errors = Improved Programming.
    My Site

  12. #12
    SitePoint Zealot Mau's Avatar
    Join Date
    Jan 2006
    Location
    California, USA
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, it usually doesn't. I'm not sure how these are implemented, but I usually just have a giant array with all my strings. The key is equal to the phrase in English, and the value is what is displayed. So, _() is simply looking up the input in the array and returning the value.

  13. #13
    SitePoint Enthusiast
    Join Date
    Feb 2004
    Location
    Montreal
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Gettext works with a sort of compiled language file. Each language must be manually translated, thus the translations are as good as the translators. Basically, it is a built in method for having a global language array. The major difference is that the keys to the array are the full text of the original message. So for example echo _("Invalid filename") instead of echo $_LANG['INVALID_FILE'];.

    Also, someone (don't have the link offhand) implemented a PHP native version of the gettext library in case the server doesn't support it.

  14. #14
    SitePoint Enthusiast duff_beer's Avatar
    Join Date
    Jul 2003
    Location
    up in the clouds
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by b1ind
    Also, someone (don't have the link offhand) implemented a PHP native version of the gettext library in case the server doesn't support it.
    That'd be PEAR::File_Gettext

    Also, you may have a look at PEAR::Translation2 that supports multiple drivers/containers: database, xml file, gettext .po and .mo files, ...

  15. #15
    SitePoint Guru BerislavLopac's Avatar
    Join Date
    Sep 2004
    Location
    Zagreb, Croatia
    Posts
    830
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Ezku
    You left out YAML.
    Quote Originally Posted by BerislavLopac
    - another markup in a separate file: JSON, YAML, CSV...
    No I didn't.
    Quote Originally Posted by Ezku
    INI is well-suited for this task if you ask me. It supports up to two levels of depth (1. language, 2. the translated string - a perfect fit), is very readable and readily available in PHP.
    Personally, I prefer the approach where each language has its own file, as you very rarely need more than one language at the same time. Then I use INI file sections for sections of application or individual pages, depending on the context.

  16. #16
    SitePoint Guru BerislavLopac's Avatar
    Join Date
    Sep 2004
    Location
    Zagreb, Croatia
    Posts
    830
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Fjoggen
    I recommend that you use getText, after all that's what it is made for.

    Much easier than using arrays, ini or xml files.
    Easier to use, but not easier to prepare. And in my experience the latter is usually much more work than the former.

  17. #17
    PEACE WILL WIN abalfazl's Avatar
    Join Date
    Feb 2005
    Location
    Beyond the seas there is a town
    Posts
    711
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I shall build a boat,I shall cast it in the water,
    I shall sail away from this strange earth,
    Where no one awaken the heroes in the wood of love

  18. #18
    SitePoint Guru Galo's Avatar
    Join Date
    May 2005
    Location
    Holland!
    Posts
    852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Sicloan
    You could do something like vbulletin does and use a Phrase system. in which you store all your phrases as $phrase['blah'] in your template system, and replace the phrases with the correct language
    Looks a bit like to much overhead from my perspective...

    try to mock up a system which alows you to retreive a string from a specific file

    like messages.error.en.xml, messages.error.nl.xml, messages.error.de.xml

    - EN
    <messages cat="error">
    <message key="printerOnFire" value="You're printer is on fire">
    </messages>

    - NL
    <messages cat="error">
    <message key="printerOnFire" value="Je printer staat in de fik!">
    </messages>

    Based on the language your end-user has chose you can now load the correct file always automaticly.
    Business as usual is off the menu folks, ...

  19. #19
    SitePoint Zealot agoossens's Avatar
    Join Date
    Mar 2004
    Location
    Adelaide, Australia
    Posts
    124
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Galo
    Looks a bit like to much overhead from my perspective...
    Since when did XML have less overhead than a PHP array?

    I personally have files labelled "lang_whatever.php", and then include() them when I need to based on configuration information, user preferences, etc. Those files have a bunch of constants in them that I scatter throughout the code. I've tried gettext - never again.
    This space for rent.

  20. #20
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Location
    The Netherlands
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Somtimes I use lang_[name].php files with arrays for this, and sometimes I use XML for storing language information, somewhat like;
    lang_english/errors.ini
    Code:
    ; This section provides the various sorts of errors triggered by users (bad URL etc)
    [User_Errors]
    BadURL = You've provided a URL that doesn't exist or that has the wrong style. Please return to the homepage, or try the following. [snip]
    WrongLocation = This location doesn't exists.
    The last solutions really works great for me

  21. #21
    SitePoint Zealot sleepeasy's Avatar
    Join Date
    Sep 2003
    Location
    Bristol, UK
    Posts
    145
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    gettext will always be the best solution (in terms of look-up speed). If the extension is available to you (and you can get the darn thing to work), use it. Otherwise just put all your strings in an array and index them by some ID, with one array per language. Using XML will always be slower no matter how the XML is formatted, etc.

    Read this great tutorial if you're new to the gettext extension.

    The follow up post is worth reading as it compares the peformance of gettext (extension), PHP gettext, and array lookup.
    Always open to question or ridicule

  22. #22
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How then the charset will work? i mean, i can use different languages, but what i cam do, to make sure, every language will show properly.

    I am in that situation right now. I did not implement the ideas from here yet, but if i do, then would everything show properly?

    Alongwtih those INI or XML files, what i need to do extra to make sure.
    ---------------------------
    Errors = Improved Programming.
    My Site

  23. #23
    SitePoint Wizard dreamscape's Avatar
    Join Date
    Aug 2005
    Posts
    1,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jaswinder_rana
    How then the charset will work? i mean, i can use different languages, but what i cam do, to make sure, every language will show properly.
    Use UTF-8 character set for all languages.

  24. #24
    SitePoint Guru Galo's Avatar
    Join Date
    May 2005
    Location
    Holland!
    Posts
    852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by agoossens
    Since when did XML have less overhead than a PHP array?

    I personally have files labelled "lang_whatever.php", and then include() them when I need to based on configuration information, user preferences, etc. Those files have a bunch of constants in them that I scatter throughout the code. I've tried gettext - never again.
    It's not the array i'm worried about

    "template system, and replace the phrases with the correct language"



    same goes for xml, but at least we are not parsing complete templates
    Business as usual is off the menu folks, ...

  25. #25
    SitePoint Guru Galo's Avatar
    Join Date
    May 2005
    Location
    Holland!
    Posts
    852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sleepeasy
    gettext will always be the best solution (in terms of look-up speed). If the extension is available to you (and you can get the darn thing to work), use it. Otherwise just put all your strings in an array and index them by some ID, with one array per language. Using XML will always be slower no matter how the XML is formatted, etc.

    Read this great tutorial if you're new to the gettext extension.

    The follow up post is worth reading as it compares the peformance of gettext (extension), PHP gettext, and array lookup.
    agreed...
    Business as usual is off the menu folks, ...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •