1

在 django.po 我有这个。

msgid "%(message)s come from weixiang http:///www.iweix.cn "
msgstr "%(message)s 来自微X http:///www.iweix.cn"

并且在我看来,(我添加了 # - - coding: utf-8 - -) 。

sina_weibo_post(self.user,_("%(message)s come from weixiang http:///www.iweix.cn ")%{"message":self.photo.desc},photo_adr)

我得到了错误:

sina_weibo_post(self.user,_("%(message)s come from weixiang http:///www.iweix.cn")%{"message":self.photo.desc},photo_adr)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position 12: ordinal not in range(128)

我该如何解决?谢谢。

4

2 回答 2

3

请检查您在 po 文件中是否有这样的标题:

msgid ""
msgstr ""
"Project-Id-Version: 1.0.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-10-04 13:06-0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: XXXXX\n"
"Language-Team: Es XXXX\n"
"Language: Es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

这一行非常重要:

"Content-Type: text/plain; charset=UTF-8\n"
于 2013-10-10T12:00:27.030 回答
1

另一个可能的解决方法是使用ugettextugettext_lazy代替gettextgettext_lazy如果您正在使用 Python 2 和 Django <=1.11,如此处建议的那样:Django Translation UnicodeDecodeError

于 2018-10-22T11:53:46.847 回答