i18n在Django 1.9.1中的模板中出现问题

时间:2016-01-04 12:39:32

标签: django django-templates django-i18n

目前正在尝试升级Django 187 - > 191但我的模板文件中的翻译遇到意外问题。首次出现模板中的trans-tag时,我会得到以下错误。在我看来,当没有找到mo / po文件或匹配此字符串时,ugettext没有正确默认(目前没有使用no / norwegian的翻译文件,所以应该坚持使用现有名称)。

所有翻译都在很长一段时间内正常运作,所以这出乎意料......

有什么想法吗?

   File "/home/tss/webapps/shoot_django/lib/python2.7/django/templatetags/i18n.py", line 89, in render
     value = render_value_in_context(output, context)
   File "/home/tss/webapps/shoot_django/lib/python2.7/django/template/base.py", line 1022, in render_value_in_context
     value = force_text(value)
  File "/home/tss/webapps/shoot_django/lib/python2.7/django/utils/encoding.py", line 78, in force_text
     s = six.text_type(s)
   File "/home/tss/webapps/shoot_django/lib/python2.7/django/utils/functional.py", line 114, in __text_cast
    return func(*self.__args, **self.__kw)
   File "/home/tss/webapps/shoot_django/lib/python2.7/django/utils/translation/__init__.py", line 85, in ugettext
    return _trans.ugettext(message)
   File "/home/tss/webapps/shoot_django/lib/python2.7/django/utils/translation/trans_real.py", line 318, in ugettext
     return do_translate(message, 'ugettext')
   File "/home/tss/webapps/shoot_django/lib/python2.7/django/utils/translation/trans_real.py", line 298, in do_translate
    result = getattr(translation_object, translation_function)(eol_message)
   File "/usr/local/lib/python2.7/gettext.py", line 400, in ugettext
     tmsg = self._catalog.get(message, missing)
 AttributeError: 'NoneType' object has no attribute 'get'

...

EventToCommand

...

InvokeCommandAction.

1 个答案:

答案 0 :(得分:0)

当您尝试设置LANGAUGES设置中未列出的语言时会发生这种情况。对我来说,这是由无效的用户偏好(过去某些时候可能有效)引起的,而translation.activate只是没有任何错误。

这是由https://github.com/django/django/commit/f0a4ff2b118cbc3b7f9ac28a7d9e355288b546c0

引起的 PS:我已经报告了这一点,因为我认为这是不应该发生的回归:https://code.djangoproject.com/ticket/26050

PS2:这只是表明我无法搜索现有报告,因为它已经修复了https://code.djangoproject.com/ticket/26046的副本。