Sunday, November 18, 2007

Internationalization/Localization Cheat Sheet

ISO 639-2 Language Codes live here:
http://www.loc.gov/standards/iso639-2/php/code_list.php

Command Line Tools
xgettext will collect all your strings for you from a file or set of files into a po file.

msgfmt will turn your po files into mo files.


info gettext will get you all the info you need to use the GNU gettext utility.


File Structure
Stick your po and mo files into a structure like this:

/src
/locale/en/LC_MESSAGES/messages.mo
messages.po
es/LC_MESSAGES/messages.po
messages.mo


PHP Functions
putenv ("LC_ALL=es"); sets your locale to Spanish.
bindtextdomain ("messages", "./locale"); shows where to find the translation tables.
textdomain ("messages"); says what domain we're using.

Internationalize your strings in PHP using the handy-dandy underscore operator.
print(_("Hello World"));

More info on gettext functions in PHP:
http://php.net/gettext

No comments: