Re: [pygtk] Translation, gtk labels, and gettext
jzgoda at o2.pl
Fri Dec 7 00:43:00 WST 2007
Dnia 6 grudnia 2007 15:17 John Dennis <jdennis at redhat.com> napisał(a):
> Caleb Marcus wrote:
> > I'm planning to make my application translatable with gettext. Do I have
> > to make the text in my gtk stock buttons and things like that use
> > gettext, or will they automatically translate due to their use of gtk
> > stock things?
> Here are a few quick hints to make life easier. Do not use Python
> unicode strings in your application, use UTF-8 and put it in a normal
> Python string. Why? Because all the libraries you're linking with expect
> UTF-8, not unicode.
Contrary to this opinion, I have no problems when using unicode objects. Moreover, PyGTK happily accepts unicode objects passed as method arguments. Unfortunately, this does not work other way (you will always get utf-8 encoded byte strings).
While sticking to one encoding and using byte strings is one of ways to not get into UnicodeEncode/DecodeError's, but not the recommended one. Current advice is to use unicode objects in the code and encode them to byte strings when outputting. Eventually in Python3 current unicode will become 'str' and current 'str' will become bytes type.
> Use gettext.install() as soon as your application starts up, that will
> install _() as a global symbol. Tell gettext you're using UTF-8,
> otherwise it will default to unicode and you will have a raft of
> problems. (If you're not providing a program, but rather library modules
> another program will load then the technique is different).
> gettext.install(domain = program_name),
> unicode = False,
> codeset = 'utf-8')
My applications use unicode=True without any problems. In such case, there's no need to specify codeset.
There is very good FAQ entry on internationalizing PyGTK program in PyGTK FAQ.
More information about the pygtk