[pygtk] Translate glade strings on a gettext based application (not based on locale)

Cristian NAVALICI cristian.navalici at gmail.com
Tue Jul 14 21:22:45 WST 2009


Hello everyone,

I try to build a python application based on pygtk. For GUI development
I used glade3 with the translatable strings option.

I've created all the PO, MO files needed, starting application with
different LANG constants in command line gives me expected results (e.g.
LANG="ro_RO.UTF-8" bin/application.py). So everything seems to be
working as expected for now.

My goal is to be able to change language inside the application, and not
only based on locale settings.

If I put in __init__.py

<code>
lang = gettext.translation(GETTEXT_DOMAIN, LOCALE_PATH,
languages=['ro'], fallback = True)
lang.install()
_ = lang.gettext

for module in gtk.glade, gettext:
    module.bindtextdomain(GETTEXT_DOMAIN, LOCALE_PATH)
    module.textdomain(GETTEXT_DOMAIN)

print _("_File")
</code>


the _File is translated correctly (GETTEXT_DOMAIN, LOCALE_PATH defined
above, no problem about that).
lang.install() seems to work ok, _() is present.

But the strings are not translated in the glade file! So, if I have some
string to be translated inside my modules, it works, but not for glade
file. I repeat, all the strings seem to be translated correctly when I
use LANG to start up application (e.g. LANG="ro_RO.UTF-8"
bin/application.py) but not if I hardcoded the change. Or there is
another way to do it?

Have any idea?
Thanks

Cristian Navalici


More information about the pygtk mailing list