我使用 python gettext 模块。当我使用 language=en_US 时没问题,但当我使用其他语言(例如:vi_VN)时会引发错误。我做错了什么吗?
\n\ntrans = gettext.translation(domain, os.path.join(os.getcwd(), \'locales\'), [language])\nRun Code Online (Sandbox Code Playgroud)\n\n我的项目中的 locales 文件夹:
\n\nlocales/\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 en_US\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 LC_MESSAGES\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 i38.po\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 vi_VN\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 LC_MESSAGES\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 i38.mo\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 i38.po\nRun Code Online (Sandbox Code Playgroud)\n\n错误
\n\nTraceback (most recent call last):\n File "root.py", line 25, in <module>\n trans = gettext.translation(domain, os.path.join(os.getcwd(), \'locales\'), [language])\n File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/gettext.py", line 410, in translation\n t = _translations.setdefault(key, class_(fp))\n File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/gettext.py", line 160, in __init__\n self._parse(fp)\n File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/gettext.py", line 300, in _parse\n catalog[str(msg, charset)] = str(tmsg, charset)\nUnicodeDecodeError: \'ascii\' codec can\'t decode byte 0xe1 in position 5: ordinal not in range(128)\nRun Code Online (Sandbox Code Playgroud)\n
小智 1
添加到文件中
\n\nmsgid ""\nmsgstr ""\n"Project-Id-Version: django\\n"\n"Report-Msgid-Bugs-To: \\n"\n"POT-Creation-Date: 2017-01-19 16:49+0100\\n"\n"PO-Revision-Date: 2017-09-23 18:54+0000\\n"\n"Last-Translator: Primo\xc5\xbe Verdnik <primoz.verdnik@gmail.com>\\n"\n"Language-Team: Slovenian (http://www.transifex.com/django/django/language/"\n"sl/)\\n"\n"MIME-Version: 1.0\\n"\n"Content-Type: text/plain; charset=UTF-8\\n"\n"Content-Transfer-Encoding: 8bit\\n"\n"Language: sl\\n"\n"Plural-Forms: nplurals=4; plural=(n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n"\n"%100==4 ? 2 : 3);\\n"\nRun Code Online (Sandbox Code Playgroud)\n