Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!

 



Forgot your password?
typodupeerror
PHP

Journal roboros's Journal: Multi-language web applications in PHP? 7

I am going to build a web application in PHP. The application needs to provide the user interface in several languages, and will have rather complicated application logic including database access. Of course I will separate the logic from the presentation, but what is the best way to implement multi-language support?

I've briefly tried using gettext together with plain PHP files in the presentation layer, which works but makes it hard to use HTML editors for editing the user interface. Another option would be to simply make a copy of all presentation layer files for each language. I'm sure there are better alternatives.

If you have any experience with multi-language PHP applications, I would really like to hear about it. Which techniques did you use, and how did they perform in practise? Thanks in advance.

This discussion has been archived. No new comments can be posted.

Multi-language web applications in PHP?

Comments Filter:
  • I tried doing something like this about a year ago. Use a templating engine like smarty to separate your program logic from your presentation. You will either need to use different templates for each language, or populate a template with language data from a DB. Be careful though, PHP isn't 100% UTF compatible, and I've had some weird things happen.
    • Thanks for your reply! I will most likely start by using different templates for each language. The main downside I see with that is that when the templates in the base language are updated (text or layout), someone will have to manually go through the translated templates and merge the changes, right?

      Regarding UTF, the current project will only support English and a few other Western languages, and I can probably get away with just using ISO Latin 1 for all of them. But I will certainly keep your warning

      • Well you're always going to need to change the text. If you are smart with templating though, you can layer your templates. For instance, using HTML::Template style templates, I can template the following HTML:

        <TMPL_IF NAME="francais">
        <TMPL_INCLUDE NAME="parle_vous.tmpl">
        </TMPL_IF>
        <TMPL_I F NAME="english">
        <TMPL_INCLUDE NAME="speak_english.tmpl">
        </TMPL>

        The template above uses templates within templates. So, you can keep three templates: 1 for the layout, and 2 se

  • Hi,

    There are imho three ways of doing this. You can a) use gettext, b) a database or c) an array containing the strings (eventually using some wrapper class/functions)

    Gettext:
    Really nice but not installed on every host, so if you want to share the app it won't run everywhere. Maintainig is a bit harder, since youneeed some special tools, but, since there are many programsusing gettext there are many tools helping with the translation.

    Database:
    Simple changing texts with a browserinterface (or a datab

    • Thanks for the info!

      The project I'm working on is not that big and limited to a few Western languages. Most of the things that need translation are part of the static user interface, users won't be able to edit it.

      I have done some simple tests using gettext, but not used it for any serious work. Do you know how fast it is?

      For a start I will separate the user interface from the application logic and probably use a template engine like Smarty as recommended by KingOfBLASH in his replies above. That woul

Matter cannot be created or destroyed, nor can it be returned without a receipt.

Working...