GNU Info

Info Node: (python2.1-lib.info)GNU gettext API

(python2.1-lib.info)GNU gettext API


Next: Class-based API Prev: gettext Up: gettext
Enter node , (file) or (file)node

GNU `gettext' API
-----------------

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.

`bindtextdomain(domain[, localedir])'
     Bind the DOMAIN to the locale directory LOCALEDIR.  More
     concretely, `gettext' will look for binary `.mo' files for the
     given domain using the path (on UNIX):
     `LOCALEDIR/LANGUAGE/LC_MESSAGES/DOMAIN.mo', where LANGUAGES is
     searched for in the environment variables `LANGUAGE', `LC_ALL',
     `LC_MESSAGES', and `LANG' respectively.

     If LOCALEDIR is omitted or `None', then the current binding for
     DOMAIN is returned.(1)

`textdomain([domain])'
     Change or query the current global domain.  If DOMAIN is `None',
     then the current global domain is returned, otherwise the global
     domain is set to DOMAIN, which is returned.

`gettext(message)'
     Return the localized translation of MESSAGE, based on the current
     global domain, language, and locale directory.  This function is
     usually aliased as `_' in the local namespace (see examples below).

`dgettext(domain, message)'
     Like `gettext()', but look the message up in the specified DOMAIN.

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.')

---------- Footnotes ----------

(1)  The default locale directory is system dependent; e.g. on RedHat
Linux it is `/usr/share/locale', but on Solaris it is
`/usr/lib/locale'.  The `gettext' module does not try to support these
system dependent defaults; instead its default is
``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.


automatically generated by info2www version 1.2.2.9