Internationalization and Localization

Index of All Documentation » Wing Pro Reference Manual » Scripting and Extending Wing » Script Syntax »


String literals and docstrings defined in scripts can be flagged for translation using the gettext system. To do this, the following code should be added before any string literals are used:

import gettext
_ = gettext.translation('scripts_example', fallback=1).gettext
_i18n_module = 'scripts_example'

The string 'scripts_example' should be replaced with the name of the .mo translation file that will be added to the resources/locale localization directories inside the Wing installation.

Subsequently, all translatable strings should be passed to the _() function as in this code example:

kMenuName = _("Test Base")

The separate _i18n_module attribute is needed to tell Wing how to translate docstrings, which cannot be passed to _().

The pygettext.py script included with Python can be used to extract and merge strings into a *.po file and then convert that file into an *.mo file. See Python's documentation for gettext for details.