[Python-de] Internationalisierung mittels gettext *würg*

Felix temp01 at directbox.com
Mi Sep 21 13:56:11 CEST 2011


Hallo zusammen,

ich versuche verzweifelt es einmal hinzubekommen, einige Strings zu
lokalisieren.

Mein Modul gettextExample.py ist daher sehr einfach gehalten und sieht
wie folgt aus:

------------------------------------------------------------------------------------------------------
BEGIN gettextExample.py
import gettext
import locale
import random

current_locale, encoding = locale.getdefaultlocale()
locale_path = './locale/' + current_locale + '/LC_MESSAGES/'
print locale_path

trans = gettext.translation('myapp', 'locale', [current_locale])
trans.install()

values = []
while True:
    w = raw_input(_(u"Please enter a value: ")) #wrapper
    if not w:
        break
    values.append(w)
print _(u"The random choice is: %s") % random.choice(values) #wrapper

------------------------------------------------------------------------------------------------------
END gettextExample.py

Dieses kompilierte Sprachfile "myapp.mo" (Yippiyeihooo, ich habs
hinbekommen) liegt auch schon unter:

<pyModulDir>/locale/de_DE/LC_MESSAGES

wenn ich nun obige Datei ausführe, kommt aber immer:

------------------------------------------------------------------------------------------------------
BEGIN output-shell

Traceback (most recent call last):
  File "Z:\_PROJECTS\_PYTHON\0007_MathStrDate\gettextExample.py", line
16, in <module>
    trans = gettext.translation('myapp', 'locale', [current_locale])
  File "C:\Programme\Python\lib\gettext.py", line 478, in translation
    t = _translations.setdefault(key, class_(fp))
  File "C:\Programme\Python\lib\gettext.py", line 180, in __init__
    self._parse(fp)
  File "C:\Programme\Python\lib\gettext.py", line 337, in _parse
    tmsg = unicode(tmsg, self._charset)
LookupError: unknown encoding: CHARSET

------------------------------------------------------------------------------------------------------
END output-shell

Es liegt also wohl an dieser Zeile:

trans = gettext.translation('myapp', 'locale', [current_locale])

Hat vielleicht einer Ahnung von Internationalisierung und kann mir
helfen? Ich raffs nicht ...

Beste Grüße

Felix


Mehr Informationen über die Mailingliste python-de