PyGTK localisation on Win32

Jarek Zgoda jzgoda at o2.usun.pl
Tue Mar 25 16:11:05 EDT 2008


jwesonga pisze:
> I've built an app on linux which we have managed to localise into at
> least three languages, the app runs well using this command LANG=fr_FR
> python app.py which would translate the app into french. We've tried
> the replicate the same principle on windows but so far nothing works,
> the app will need to be translated into other languages that have no
> locale, in windows is there a way to have Glade load values from a
> textfile instead of trying to use the .mo files?

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.

-- 
Jarek Zgoda
http://zgodowie.org/

"We read Knuth so you don't have to" - Tim Peters



More information about the Python-list mailing list