Showing posts with label gettext. Show all posts
Showing posts with label gettext. Show all posts

Thursday, June 30, 2011

Gettext and codesets. UTF-8 in particular

For the longest time, Japanese translations weren't working and kept returning ???? instead of the correct Japanese characters. A college finally found the solution:

bind_textdomain_codeset("messages", 'UTF-8');


where "messages" is the text domain that was bound with the textdomain command.

Stupidly difficult bug to tackle.

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