Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 获取\u当前\u语言\u bidi未按预期工作_Python_Django_Internationalization - Fatal编程技术网

Python 获取\u当前\u语言\u bidi未按预期工作

Python 获取\u当前\u语言\u bidi未按预期工作,python,django,internationalization,Python,Django,Internationalization,我已将django.template.context\u processors.i18n添加到context\u processors, 我已经在中间件类中添加了django.middleware.locale.localemidleware,我几乎可以肯定这是不相关的,但为了以防万一,我也在urlpatterns中添加了url(r'^i18n/',include('django.conf.url.i18n') 我成功地创建了一个.po文件,编译了一个.mo文件,并且翻译(其中有要翻译的字符串)

我已将
django.template.context\u processors.i18n
添加到context\u processors, 我已经在中间件类中添加了
django.middleware.locale.localemidleware
,我几乎可以肯定这是不相关的,但为了以防万一,我也在urlpatterns中添加了
url(r'^i18n/',include('django.conf.url.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 %}
{%extends“page.html”%}
{%load i18n%}
{%get_当前语言为语言代码%}
{%get_current_language_bidi as language_bidi%}
{%block title%}{%trans“翻译测试”%}{%endblock%}
{%block page_main_content%}
  • 当前语言为{{language_CODE}}
  • {%if语言_BIDI%}
  • 当前语言是双向的
  • {%else%}
  • 当前语言不是双向的
  • {%endif%}
{%endblock%}
我得到的是:

  • 目前的语言是he_IL
  • 当前语言不是双向的

我会假设我导入了不正确的内容或配置了错误的设置,但
get\u current\u language
显然工作正常。那么为什么django错误地为
get\u current\u language\u bidi
返回False呢

我认为你的语言偏好来源有问题。根据,预期的分隔符是破折号。因此,Django可能认为,
he_IL
是一种未知的语言,因此默认情况下它不是双向的

你应该,并确保它给出
he-il
he
而不是
he-il