Skip to content

Internationalization

lancew edited this page Sep 13, 2010 · 1 revision

As of version 0.3.0 simple Internationalisation using Gettext is possible.

The language support is in the /locale/xx/LC_MESSAGES/ directories, using the standard two letter abbreviations for languages, i.e. en for English, es for Spanish etc. Native speakers can assist the project by editing the messages.po file in the directory. The .po file is then used to create the .mo file.

Admin work.

Within the code include the following for any outputs that require translation like as follows:

<?php echo _(“Home”); ?>

The _( function is where translations live.

When changes are made to the source code (in the build process), run the following commands:

xgettext ../../../views/*.php

from the LC_MESSAGES folder in terminal to create the .po for all the files in the views directory. Then run :

msgfmt messages.po -o messages.mo

from the LC_MESSAGES folder in terminal to create the .mo file, this should be all that is required.

For translations, copy the messages.po file into the appropriate /locale/xx/LC_MESSAGES folder. Then edit the file, filling in the msgstr "" blocks with the appropriate translations. You can then run the msgfmt command as above.

We need to add code into the app to manage which language is displayed. Including the translation is a case of including

// Specify location of translation tables
bindtextdomain (“messages”, “./locale”);

// Choose domain
textdomain (“messages”);

in the main index.php file and also selecting the language using:

<?php
// Set language to Spanish
putenv (“LC_ALL=es”);
?>

Which is currently in default_layout.php this all needs tidying up.

Clone this wiki locally