Changes
Jump to navigation
Jump to search
Line 2:
Line 2:
− === Step 2: ===+
+
+
− === How do I ensure that a text string is correctly translated to another language when appropriate (for internationalization)? ===+
+
+
+
+
+
+
+
− 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."+
− from gettext import gettext as _
− ...
− #Make sure 'hello world' translates
− print _('hello world')
Development Team/Almanac/Internationalization (view source)
Revision as of 15:39, 17 July 2008
, 15:39, 17 July 2008→Broad Steps to Internationalize/Localize Your Code
=== 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: ===