PyGTK localisation on Win32

Sukhov Dmitry dmitry.sukhov at gmail.com
Thu Mar 27 08:21:08 EDT 2008


>
> I had no problem with using standard gettext way of doing i18n on
> Windows with PyGTK an Glade, apart some quirks with LANG environment
> variable. Basically, the code that works looks like this:
>
>     import gettext, locale
>     locale.setlocale(locale.LC_ALL, '')
>     if os.name == 'nt':
>         # windows hack for locale setting
>         lang = os.getenv('LANG')
>         if lang is None:
>             defaultLang, defaultEnc = locale.getdefaultlocale()
>             if defaultLang:
>                 lang = defaultLang
>         if lang:
>             os.environ['LANG'] = lang
>     gtk.glade.bindtextdomain(appname, translation_dir)
>     gtk.glade.textdomain(appname)
>     gettext.install(appname, translation_dir, unicode=True)
>
> Be aware, that you can not change the locale setting from the command
> line like you do on Linux.
>

I have the same problem. I did all as you wrote. gettext translations
do work fine. But translations in glade does not work.

The only way to turn it on is to set environment variable LANG
explicitly before program run:
set LANG=ru_RU
python test.py





More information about the Python-list mailing list