Development Team/Almanac/Internationalization: Difference between revisions
| Line 2: | Line 2: | ||
=== Step 1: === | === Step 1: === | ||
To ensure that string output from your activity is correctly translated, you would use the gettext utility. The code below imports gettext, renaming it as '_' for code brevity. Then, whenever there is a string that you want to make sure is translated based on language settings, you simply pass it to the _() function. According to the [http://docs.python.org/lib/node731.html Python Reference Library], gettext will "return the localized translation of message, based on the current global domain, language, and locale directory." | |||
The code snippet below is part of a larger UI creation routine that creates a sugar.graphics.Notebook object and three pages for that notebook. Each page label should be appropriately translated. | |||
<pre> | |||
from gettext import gettext as _ | |||
... | |||
#Add the pages to the notebook. | |||
top_container.add_page(_('First Page'), first_page) | |||
top_container.add_page(_('Second Page'), second_page) | |||
top_container.add_page(_('Third Page'), third_page) | |||
</pre> | |||
=== Step 2: === | |||