[pygtk] Re: pygtk libglade and gettext troubles
stas.zytkiewicz at gmail.com
Thu Mar 2 15:57:29 WST 2006
On 3/1/06, stas zytkiewicz <stas.zytkiewicz at gmail.com> wrote:
> Why doesn't this work?
I just found the answer and I will post it here, perhaps it's useful for others.
> I have this inside my (simple) module:
> import locale
> import gettext
> APP = 'gvr_gtk'
> DIR = '/usr/local/share/locale'
> locale.setlocale(locale.LC_ALL, '')
> gettext.bindtextdomain(APP, DIR)
> gettext.install(APP, DIR, unicode=1)
> gtk.glade.bindtextdomain (APP, DIR)
> gtk.glade.textdomain (APP)
> And I call libglade like this:
> self.glade = gtk.glade.XML(self.glade_path, main_widget_name, domain=APP)
> I have a Dutch translated gvr_gtk.mo inside /usr/local/share/locale/nl/....
> But when I start my app like this, it stays in English :-(
> LANG=nl_NL at euro python myapp.py
It seems that libglade and gettext uses different environment locales.
The python gettext, which is used by the script to provide
localization of any string
except the ones inside the glade xml file, checks the 'LANG' env
variable to determine
the language to use.
The gtk.glade gettext implementation, which takes care of the strings
inside the glade
xml/widgets, checks the 'LANGUAGE' env variable.
So in order to have localization of *all* strings you must set them both.
If I start my app like this everything works well:
LANG=nl_NL at euro LANGUAGE=nl_NL at euro python myapp.py
However I feel it's a bug that gtk.glade doesn't check the LANG var as
the Python gettext
does. Whatever reason there is for only checking the LANGUAGE var I
think that if
the Python gettext checks LANG so must the (py)gtk.glade. IMHO.
More information about the pygtk