In order to prepare your code for I18N, you need to look at all the
strings in your files. Any string that needs to be translated
should be marked by wrapping it in
_('...') - i.e. a call to
the function _(). For example:
filename = 'mylog.txt' message = _('writing a log message') fp = open(filename, 'w') fp.write(message) fp.close()
In this example, the string
'writing a log message' is marked as
a candidate for translation, while the strings
'w' are not.
gettext package provides a tool, called
xgettext, that scans C and C++ source code looking for these
specially marked strings. xgettext generates what are
called .pot files, essentially structured human readable files
which contain every marked string in the source code. These
.pot files are copied and handed over to human translators who write
language-specific versions for every supported natural language.
For I18N Python programs however, xgettext won't work; it doesn't understand the myriad of string types support by Python. The standard Python distribution provides a tool called pygettext that does though (found in the Tools/i18n/ directory).6.3 This is a command line script that supports a similar interface as xgettext; see its documentation for details. Once you've used pygettext to create your .pot files, you can use the standard GNU gettext tools to generate your machine-readable .mo files, which are readable by the GNUTranslations class.
How you use the gettext module in your code depends on whether you are internationalizing your entire application or a single module.