Gettext in SubjectsPlus

From SubjectsPlus
Jump to: navigation, search

Instructions to implement gettext in SubjectsPlus

Set Up the Directory Structure

cd into the sp directory

Create a directory called locale. Within locale, create a directory for each language that you want to be able to support. You don't need to create one for English. Name these directories using the ISO language/country codes (e.g., es_ES for Spanish, fr_FR for French).

Within each of your language directories, create a directory called LC_MESSAGES.

Make the PO Files

cd to the sp directory

Enter the command:

 find * -name '*.php' | xargs xgettext

This will create a file called messages.po.

Edit the line near the beginning of messages.po that refers to the Content-Type by specifying a character set to be used. For most languages that use Roman letters, iso-8859-1 should work. Save your changes.

Copy this file into each of the language directories as follows:

 cp messages.po locale/es_ES/LC_MESSAGES
 cp messages.po locale/fr_FR/LC_MESSAGES


Edit the PO Files

Now you need to enter the alternate-language text in each of the PO files that you have created. Most of the PO file consists of pairs of msgid and msgstr lines, the former containing the string to be translated. You'll need to fill in the msgstr yourself. So, for instance, you might edit the first message in sp/locale/es_ES/LC_MESSAGES/messages.po as follows:

 #: control/login.php:37
 msgid "Please enter your login and password to proceed."
 msgstr "Por favor ingrese su nombre de usuario y contraseña para continuar."

Make the MO Files

Once you have done the necessary editing in the PO files, you need to create an MO file for each of them. cd into the directory with the PO file and type the command:

 msgfmt messages.po

This will create the required mo file.

If you need to update translation files

Let's say new strings are added to the program that require translation. You can generate a new PO file as described above and then merge your files as follows:

 msgmerge -o messages.out messages.po

where messages.po is your old PO file; is the (probably mostly blank) PO file with the new strings; and messages.out is the output file to be created. Once you have done this and checked messages.out to make sure the new strings are there, rename messages.out as messages.po and re-create the MO file.

Of course, if you're only adding one or two strings, it's probably simpler to just add them to the old PO file manually and then re-create the MO file.