您好我有下一个情况:
在settings.py中:
LANGUAGE_CODE = 'ru-ru'
LOCALE_PATHS = (
os.path.join(BASE_DIR, "locale"),
)
LANGUAGES = [
('en', 'English'),
('ru', 'Russian'),
]
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
在urls.py中我有:
url(r'^i18n/', include('django.conf.urls.i18n')),
#url(r'^jsi18n/$', javascript_catalog, js_info_dict, name='javascript-catalog'),
url(r'^admin_tools/', include('admin_tools.urls')),
语言变更表:
<form id="lang-bar" action="{% url 'set_language' %}" method="post">{% csrf_token %}
<input name="next" type="hidden" value="{{ redirect_to }}" />
<select name="language">
{% get_current_language as LANGUAGE_CODE %}
{% get_available_languages as LANGUAGES %}
{% get_language_info_list for LANGUAGES as languages %}
{% for language in languages %}
<option value="{{ language.code }}"{% if language.code == LANGUAGE_CODE %} selected="selected"{% endif %}>
{{ language.name_local }} ({{ language.code }})
</option>
{% endfor %}
</select>
<input class="button" type="submit" value="{% trans 'Change' %}" />
</form>
我已经创建了语言环境并进行了翻译和编译,但是当我点击更改时,语言不会改变。它是LANGUAGE_CODE = 'en-us'
此代码工作得很好的其他项目
答案 0 :(得分:0)
很抱歉,我忘记了在{。1}中将'django.middleware.locale.LocaleMiddleware',
添加到MIDDLEWARE