Tuesday, May 3, 2011

Gettext workflow

1. Define your bindtextdomain and textdomain as
bindtextdomain('hello', '/usr/share/locale')
textdomain('hello')

2. Wrap strings to be translated in gettext('translate me') or, using the gettext alias, _('translate me').
return _('this string is to be translated');
3. Extract the strings using the xgettext utility.
xgettext -d hello -s -o hello.pot hello.c
4. Turn the .pot file into a .po file that can be passed on to the translators
msginit -l es_US -o spanish.po -i hello.pot
5. Translate the strings in the .po file
msgid "Hello\n"
msgstr "Hola\n"
6. Convert the .po file into a compiled .mo using the msgfmt utility, note that the output filename must match the domain given as the first argument to bindtextdomain and textdomain and must be placed in the location specified as the second argument to bindtextdomain
joined with the language set in setlocale or set in the environment
msgfmt -c -v -o hello.mo spanish.po
cp hello.mo /usr/share/locale/es_US/LC_MESSAGES
source