Я использую UTF-8 в своем редакторе, поэтому все строки, отображаемые здесь, имеют кодировку UTF-8 в файле.
У меня есть сценарий Python, подобный этому:
# -*- coding: utf-8 -*-
...
parser = optparse.OptionParser(
description=_('automates the dice rolling in the classic game "risk"'),
usage=_("usage: %prog attacking defending"))
Затем я использовал xgettext, чтобы получить все, и получил файл .pot, который можно сократить до:
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
#: auto_dice.py:16
msgid "automates the dice rolling in the classic game \"risk\""
msgstr ""
После этого я использовал msginit, чтобы получить de.po
, который я заполнил как это:
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: auto_dice.py:16
msgid "automates the dice rolling in the classic game \"risk\""
msgstr "automatisiert das Würfeln bei \"Risiko\""
При запуске сценария появляется следующая ошибка:
File "/usr/lib/python2.6/optparse.py", line 1664, in print_help
file.write(self.format_help().encode(encoding, "replace"))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 60: ordinal not in range(128)
Как я могу это исправить?