6.23.3.1 Localizing your module

If you are localizing your module, you must take care not to make global changes, e.g. to the built-in namespace. You should not use the GNU gettext API but instead the class-based API.

Let's say your module is called ``spam'' and the module's various natural language translation .mo files reside in /usr/share/locale in GNU gettext format. Here's what you would put at the top of your module:

import gettext
t = gettext.translation('spam', '/usr/share/locale')
_ = t.gettext

If your translators were providing you with Unicode strings in their .po files, you'd instead do:

import gettext
t = gettext.translation('spam', '/usr/share/locale')
_ = t.ugettext


See About this document... for information on suggesting changes.