updated as of: April 1, 2015
last author: Andy Theuninck
The latest documentation can be found on the
Project Wiki.
The information below may be out of date.
This is a quick primer on using gettext in conjunction with PHP
to store message strings in various languages.
In PHP
Using gettext in PHP is pretty simple. Instead of writing:
echo "I am awesome"
use on of the following:
echo gettext("I am awesome")
echo _("I am awesome")
I tend to use the underscore version. If the string hasn't been translated,
everything will still work fine. It'll just return exactly the input unmodified.
Creating / Managing Language Files
This is by no means the only method. Other tools exist for
editing these kind of files. Examples are command-line based, executed
from the pos/is4c-nf directory
First, we need a list of all the messages. This is normally in a .pot file.
Generate it like this:
find . -name '*.php' | xargs xgettext -L PHP -d pos-nf -o locale/pos-nf.pot --no-wrap -j
Try not to forget the -j option. That merges things so existing translations
in the .pot file are preserved. The .pot file is just a text file. Update the msgstr
values in it as needed.
Next, we need to translate the .pot file into a .po file. The command is this:
msgmerge -U locale/pos-nf_en_US.po locale/pos-nf.pot
Some programs can edit .po files directly.
Finally, we need to translate the .po file into a .mo file. The .mo is the
binary file that gettext actually uses to look up translations. The .po to .mo
command is this:
msgfmt -v -o locale/en_US/LC_MESSAGES/pos-nf.mo locale/pos-nf_en_US.po