13.07.2015 Views

The wxPython tutorial

The wxPython tutorial

The wxPython tutorial

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Internationalizationhttp://www.zetcode.com/wxpython/in18/In our example, we took 5 germam words from the dictionary.<strong>The</strong> default sort() function sorts these words this way: Sabotage,Schläfe, Sund, Säbel, Sünde. This is incorrect, because ingerman alphabet ä character precedes a character. To get thecorect sorting, we must use locale functions.locale.setlocale(locale.LC_COLLATE, ('de_DE', 'UTF8'))Here we set the german collate. We could use the LC_ALL optionor the more specific LC_COLLATE one.words.sort( lambda a,b: locale.strcoll(a, b) )<strong>The</strong> trick is to use a new compare function within the sort()function. We define an anonymous lambda function. <strong>The</strong> strcoll()function compares two strings and returns -1, 0, 1 exactly likethe default one, but it takes the locale settings (the collate) intoaccount. This way we have the correct sorting of words.Figure: CollateSimple TranslationIn the following example, we will demonstrate a very basictranslation.A programmer has two options. Either to use the GNU gettext orto use the <strong>wxPython</strong> catalogs. Both systems are compatible.<strong>wxPython</strong> has a class wx.Locale, which is a base for using9 de 12 27/04/2008 1:06

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!