[pygtk] gtk.Builder and translation directory
Cezary Krzyżanowski
cezary.krzyzanowski at gmail.com
Wed Mar 4 07:20:41 WST 2009
>
Answering to this post.
Actually I've got the same problem with gtk.Builder. All in-program
strings get translated superbliy, but gtk.Labels and other widgets
designed in glade-3 and converted to gtk.Builder xml don't. This is
both by using the set_translation_domain property and not doing it.
The trick that works is doing something like this:
label.set_label(gettext(label.get_label()))
or in a more automated way:
class WorkingBuilder(gtk.Builder):
def get_object(self, name):
obj = gtk.Builder.get_object(self, name)
try:
if type(obj) is gtk.Label:
obj.set_markup(_(obj.get_label()))
else:
obj.set_text(_(obj.get_text()))
except AttributeError:
pass
return obj
and using this patched Builder for all object creation. The PITA of
this is that now I have to epxplicitly use get_object on each and
every widget(label) I have defined in my GUI, even those, that I don't
actually change or modify in the code ever!
I've tried using gtk.glade and it did the job automatically, so the
translation files are deffinetely OK.
Czarek
> http://library.gnome.org/devel/gtk/2.11/GtkBuilder.html#GtkBuilder--translation-domain
>
> "The translation domain used when translating property values that
> have been marked as translatable in interface descriptions. If the
> translation domain is NULL, GtkBuilder uses gettext(), otherwise
> dgettext()."
>
> That is, GtkBuilder uses gettext directly, so whatever translations
> are loaded for gettext will be available for GtkBuilder.
> Here is how to set the translation domain and directory for gettext.
> It should then work, although I have not tested it specifically with
> GtkBuilder.
>
> >>> import gettext
> >>> gettext.bindtextdomain("myapp", "/path/to/locale/dir/")
> >>> gettext.textdomain("myapp")
>
> Laszlo
>
>
> 2009/3/1 Osmo Salomaa <otsal... at cc.hut.fi>:
> > Hello list,
> >
> > I'm trying to move from Libglade to GtkBuilder and I have one
> problem
> > remaining. gtk.glade had a bindtextdomain function (much like
> > gettext.bindtextdomain) that took the translation directory as an
> > argument. gtk.Builder seems to have a set_translation_domain
> method, but
> > it's only for defining the domain. How do I set the directory
> where to
> > search for translations to strings in GtkBuilder XML files?
> >
More information about the pygtk
mailing list