【发布时间】:2011-04-04 22:49:48
【问题描述】:
我在编辑器中使用 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)
我该如何解决这个问题?
【问题讨论】:
-
_("usage: %prog attacking defending")的类型是什么?即print type(_("usage: %prog attacking defending"))打印什么?
标签: python localization gettext