我已将django.template.context_processors.i18n
添加到context_processors,
我已将django.middleware.locale.LocaleMiddleware
添加到middleware_classes中,我几乎肯定这是不相关的,但以防万一我也将url(r'^i18n/', include('django.conf.urls.i18n'))
添加到urlpatterns。
我成功创建了.po文件,编译了.mo文件,并且翻译(有待翻译的字符串)正在加载。
但是,当我运行以下代码时:
{% extends "page.html" %}
{% load i18n %}
{% get_current_language as LANGUAGE_CODE %}
{% get_current_language_bidi as LANGUAGE_BIDI %}
{% block title %}{% trans "translation test" %}{% endblock %}
{% block page_main_content %}
<div id="some-text">
<ul>
<li>The current language is <b>{{ LANGUAGE_CODE }}</b></li>
{% if LANGUAGE_BIDI %}
<li>The current language is bidirectional</li>
{% else %}
<li>The current language is <b>not</b> bidirectional</li>
{% endif %}
</ul>
</div>
{% endblock %}
我得到的是:
- 目前的语言是he_IL
- 当前语言不双向
我会假设我导入的内容不正确或设置配置错误,但get_current_language
(显然)工作正常。那么为什么django错误地为get_current_language_bidi
返回False?
答案 0 :(得分:1)
我认为您的语言偏好来源存在问题。根据{{3}},预期的分隔符是破折号。所以Django可能会认为he_IL
是一种未知语言,因此默认情况下它不是双向的。
您应该the documentation,并确保它提供he-il
或he
而不是he_IL
。