Mar*_* M. 10 python django translation
我不明白.如果我将Accept-Language标题设置为除"en"(de,pl,es)之外的任何内容,或者甚至是不存在的内容(如xxs),则应用程序不会吐出此错误,但是当我将其设置为"恩".它只发生在Windows(最新的gettext工具)上.这是堆栈跟踪:
Traceback (most recent call last):
File "E:\projekty\python\myapp_api\_env\lib\site-packages\django\core\han
dlers\exception.py", line 39, in inner
response = get_response(request)
File "E:\projekty\python\myapp_api\_env\lib\site-packages\django\core\han
dlers\base.py", line 244, in _legacy_get_response
response = middleware_method(request)
File "E:\projekty\python\myapp_api\_env\lib\site-packages\django\middlewa
re\locale.py", line 29, in process_request
translation.activate(language)
File "E:\projekty\python\myapp_api\_env\lib\site-packages\django\utils\tr
anslation\__init__.py", line 161, in activate
return _trans.activate(language)
File "E:\projekty\python\myapp_api\_env\lib\site-packages\django\utils\tr
anslation\trans_real.py", line 238, in activate
_active.value = translation(language)
File "E:\projekty\python\myapp_api\_env\lib\site-packages\django\utils\tr
anslation\trans_real.py", line 227, in translation
_translations[language] = DjangoTranslation(language)
File "E:\projekty\python\myapp_api\_env\lib\site-packages\django\utils\tr
anslation\trans_real.py", line 129, in __init__
self._add_installed_apps_translations()
File "E:\projekty\python\myapp_api\_env\lib\site-packages\django\utils\tr
anslation\trans_real.py", line 176, in _add_installed_apps_translations
translation = self._new_gnu_trans(localedir)
File "E:\projekty\python\myapp_api\_env\lib\site-packages\django\utils\tr
anslation\trans_real.py", line 156, in _new_gnu_trans
fallback=use_null_fallback)
File "C:\Python35\lib\gettext.py", line 426, in translation
t = _translations.setdefault(key, class_(fp))
File "C:\Python35\lib\gettext.py", line 162, in __init__
self._parse(fp)
File "C:\Python35\lib\gettext.py", line 297, in _parse
self.plural = c2py(plural)
File "C:\Python35\lib\gettext.py", line 76, in c2py
raise ValueError('plural forms expression could be dangerous')
ValueError: plural forms expression could be dangerous
Run Code Online (Sandbox Code Playgroud)
我已plural-forms在我的django.po文件中正确设置:
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
Run Code Online (Sandbox Code Playgroud)
为什么会发生这种情况以及如何解决?
我找到了答案 - 错误的原因是我的无能:).我在django-admin makemessages项目的根目录中运行命令,因此在_env旁边以及所有包中.这个命令使用默认的django.po文件模板为几个项目创建了语言文件,所以它们包含类似的东西plural-forms=INTEGER和其他东西,这导致了上述错误.
| 归档时间: |
|
| 查看次数: |
1348 次 |
| 最近记录: |