Reputation: 1137
in django.po i have this .
msgid "%(message)s come from weixiang http:///www.iweix.cn "
msgstr "%(message)s 来自微X http:///www.iweix.cn"
and in view i have , (i have add # -- coding: utf-8 --) .
sina_weibo_post(self.user,_("%(message)s come from weixiang http:///www.iweix.cn ")%{"message":self.photo.desc},photo_adr)
i got the error:
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)
how can i solve it ?thanks .
Upvotes: 1
Views: 1117
Reputation: 733
Another possible fix is using ugettext
or ugettext_lazy
instead of gettext
or gettext_lazy
if your’re using Python 2 and Django <=1.11 as was suggested here: Django Translation UnicodeDecodeError
Upvotes: 2
Reputation: 3964
Please check that you have a header like this, in the po file:
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"
This line is very important:
"Content-Type: text/plain; charset=UTF-8\n"
Upvotes: 5