The gettext module defines the following API, which is very similar to the GNU gettext API. If you use this API you will affect the translation of your entire application globally. Often this is what you want if your application is monolingual, with the choice of language dependent on the locale of your user. If you are localizing a Python module, or if your application needs to switch languages on the fly, you probably want to use the class-based API instead.
If localedir is omitted or
None, then the current binding
for domain is returned.6.1
None, then the current global domain is returned, otherwise the global domain is set to domain, which is returned.
Note that GNU gettext also defines a dcgettext() method, but this was deemed not useful and so it is currently unimplemented.
Here's an example of typical usage for this API:
import gettext gettext.bindtextdomain('myapplication', '/path/to/my/language/directory') gettext.textdomain('myapplication') _ = gettext.gettext # ... print _('This is a translatable string.')
sys.prefix/share/locale. For this reason, it is always best to call bindtextdomain() with an explicit absolute path at the start of your application.