gettext newbie frustration

akbar akbarhome at gmail.com
Wed Jul 5 06:52:31 EDT 2006


Hi, I try to learn gettext and python. This is the simple program
#simplehello.py
import locale
import gettext

APP = 'simplehello'
DIR = 'locale'
locale.setlocale(locale.LC_ALL, '')
gettext.bindtextdomain(APP, DIR)
gettext.textdomain(APP)
_ = gettext.gettext

print _('Hello World')

After that I do this in my shell:
$ xgettext -k_ -kN_ -o messages.pot simplehello.py
$ cp messages.pot de.po

Edit the de.po so it will be like this:
<snip>
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

#: simplehello.py:11
msgid "Hello World"
msgstr "blabla"

Then...
$ msgfmt de.po -o locale/de/LC_MESSAGES/simplehello.mo
$ msgfmt de.po -o locale/de_DE/LC_MESSAGES/simplehello.mo
$ msgfmt de.po -o locale/de_DE.UTF-8/LC_MESSAGES/simplehello.mo

I try to run the application:
$ LANG=de_DE.UTF-8 python simplehello.py

The output is still 'Hello World' not 'blabla'.
What's wrong?

Additional facts:
$ locale -a
C
de_AT.utf8
de_BE.utf8
de_CH.utf8
de_DE.utf8
de_LU.utf8
en_AU.utf8
<snip>

$ LANG=de_DE python simplehello.py
Traceback (most recent call last):
  File "simplehello.py", line 6, in ?
    locale.setlocale(locale.LC_ALL, '')
  File "/usr/lib/python2.4/locale.py", line 381, in setlocale
    return _setlocale(category, locale)
locale.Error: unsupported locale setting

Thank you.




More information about the Python-list mailing list