我已经将django.template.context_processors.i18n
添加到上下文处理器中,
我已经将django.middleware.locale.LocaleMiddleware
添加到中间件类中,我几乎可以肯定这是不相关的,但为了以防万一,我还向urlpatterns添加了url(r'^i18n/', include('django.conf.urls.i18n'))
。在
我成功地创建了一个.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 %}
我得到的是:
- The current language is he_IL
- The current language is not bidirectional
我会假设我导入的内容不正确或者配置错误,但是get_current_language
工作(显然)很好。那么为什么django错误地为get_current_language_bidi
返回False?在
我认为你的语言偏好的来源有问题。根据the documentation,预期的分隔符是破折号。因此Django可能认为
he_IL
是一种未知语言,因此默认情况下它不是双向的。在{{cd2}而不是^ cd2}。在
相关问题 更多 >
编程相关推荐