I have python 2.7 and pygtk. I am trying to set locale language for gtk in my application but no luck. My windows is in slovak language and I would like to have button labels in my app in english. How to solve it?
I tried this but no luck (all labels are still in slovak):
import os
os.environ['LANGUAGE'] = 'en_US' #tried en_UK as well
os.environ['LANG'] = 'en_US'
os.putenv('en_US', 'LANG')
import locale
locale.setlocale(locale.LC_ALL, 'English_United Kingdom.1252' )
but when I make cmd file this works:
set LANG=en_US
something.exe
what am I doing wrong?
This is becoming a common question these days and should probably become a PyGTK FAQ.
See for example this PyGTK bug report
In short, there's a whole lot of details you're missing. For example:
1) Starting with Python 2.4, on Windows, assigning values to os.environ only
changes the copy of the environment variables Python manages and no longer has
any effect on the copy maintained by the C library (msvcr90 for Python, msvcrt
for the various GTK+ related dll's).
2) Once you take care of the above you also need to take special care of
configuring libintl. That means you'll need to bindtextdomain() and
bind_textdomain_codeset() both intl.dll and Python's gettext module.
There's probably more that I don't remember right now, but you could take a
look at my elib.intl module written specifically for what you're trying to
do (and more). When you have it working, you can simply set the LANGUAGE
environment variable to C to have the default American English.
You can do that
either from a .bat or .cmd file or by using os.environ['LANGUAGE'] = 'C' befory
you import elib.intl.