International APPs / pygettext
Martin v. Löwis
loewis at informatik.hu-berlin.de
Wed Oct 16 08:39:44 EDT 2002
Ingo Linkweiler <i.linkweiler at web.de> writes:
> msgfmt: messages.de.po: warning: Charset "CHARSET" is not a portable
> encoding name. Message conversion to user's charset might not work.
I recommend to use iso-8859-1 here.
> I ignored this warning and got a file "messages.mo"
>
> Now I run the python source. Result :-(
>
> Hello World
You need to explain it where to find the mo file. By default, it will
look into /usr/share/locale/de/LC_MESSAGES/messages.mo. You need to
define two things:
1. What is the name of your text domain? (e.g. langtest)
2. What is the location where you put .mo files?
If you use the gettext style API, you'ld do
gettext.bindtextdomain("langtest","/home/linkweiler")
def _(msg):
return gettext.dgettext("langtest",msg)
In this case, the mo file should be in
/home/linkweiler/de/LC_MESSAGES/langtest.mo.
If you use gettext.install, you do
gettext.install("langtest","/home/linkweiler")
Again, the file must be called langtest.mo, and reside in
/home/linkweiler/de/LC_MESSAGES.
If you already know the .mo file to use, you can do
_ = gettext.GNUTranslations(open("path-to-mo-file","rb")).gettext
Regards,
Martin
More information about the Python-list
mailing list