Asimov4
Asimov4

Reputation: 2854

How should I localize the interface of a PHP/MySQL website?

Are there guidelines or state of the art ways to localize a PHP/MySQL website?

The idea here is to translate buttons, page titles and messages. The language of the website would be chosen at installation time and shouldn't change.

I have started creating text files containing lists of keywords with their translation, but it feels like reinventing the wheel.

Thank you for your help.

Upvotes: 2

Views: 496

Answers (2)

Asimov4
Asimov4

Reputation: 2854

In the meantime, I found about an efficient way to build the array text file.

Wherever I want to translate a text item, I use the php gettext() function aliased _() to encapsulate it.

Then, with poedit I parse all my php files an create the translations automatically.

My generated .po (human readable) and .mo (compiled) localization files are put in:

locale/en_EN/LC_MESSAGES

I then initialize my translation application with this code:

$locale = 'en_EN';
putenv("LC_ALL=".$locale);
setlocale(LC_ALL, $locale);
bindtextdomain("messages", "locale");
textdomain("messages");

PROS:

  • This way I do not have to keep track of my various text items and creating new translations can be done by non programmers.
  • The output .po files also seem to be quite standard in their format.
  • The .po files also reference every occurrence of the text to translate in my project.
  • Another good thing is that if for some reason the .po translation files cannot be accessed, the basic text will be displayed by the gettext function.

Upvotes: 1

Debugger
Debugger

Reputation: 564

I did it once , I have added different file for different language.
Include that file , if no file included then include default (English) file.
And in that file define array ,

$array_language['welcome_msg'] = 'You are welcome';

So which file you'll include that array will show , related message else it will show default English file.

Upvotes: 2

Related Questions