The elib.intl module provides enhanced internationalization (I18N) services for your Python modules and applications.
elib.intl wraps Python’s gettext() functionality and adds the following on Microsoft Windows systems:
- automatic detection of the current screen language (not necessarily the same as the installation language) provided by MUI packs,
- makes sure internationalized C libraries which internally invoke gettext() or dcgettext() can properly locate their message catalogs. This fixes a known limitation in gettext’s Windows support when using eg. gtk.builder or gtk.glade.
See http://www.gnu.org/software/gettext/FAQ.html#windows_setenv for more information.
The elib.intl module defines the following functions:
Parameters: |
|
---|
Installs the function _() in Python’s builtin namespace, based on domain and localedir. Codeset is always UTF-8.
As seen below, you usually mark the strings in your application that are candidates for translation, by wrapping them in a call to the _() function, like this:
import elib.intl
elib.intl.install('myapplication', '/path/to/usr/share/locale')
print _('This string will be translated.')
Note that this is only one way, albeit the most convenient way, to make the _() function available to your application. Because it affects the entire application globally, and specifically Python’s built-in namespace, localized modules should never install _(). Instead, you should use elib.intl.install_module() to make _() available to your module.
Parameters: |
|
---|---|
Returns: | an anonymous function object, based on domain and localedir. Codeset is always UTF-8. |
You may find this function usefull when writing localized modules. Use this code to make _() available to your module:
import elib.intl
_ = elib.intl.install_module('mymodule', '/path/to/usr/share/locale')
print _('This string will be translated.')
When writing a package, you can usually do this in the package’s __init__.py file and import the _() function from the package namespace as needed.