语言i18n setlang不工作django 1.7.9

时间:2015-07-18 16:01:12

标签: python django internationalization

我最近尝试在我的django app中实现国际化。

我的settings.py

MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
LANGUAGE_CODE = 'en'

LANGUAGES = (
    ('en', 'English'),
    ('hu', 'Hungarian'),
)

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True
LOCALE_PATHS = (
   os.path.join(os.path.dirname(BASE_DIR), "static", "templates",     "locale"),
)

TEMPLATE_DIRS = (
    os.path.join(os.path.dirname(BASE_DIR), "static", "templates"),
)

我还将url(r'^i18n/', include('django.conf.urls.i18n')),添加到我的urls.py

我的语言变化形式如下:

<form 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 type="submit" value="{% trans "Go" %}" />
</form>

我运行了命令makemessages -l hu并填写了.po文件,然后运行了命令compilemessages

问题在于,当我尝试使用上面的表单更改语言时,我得到一个302 http响应,而django只返回到之前的相同消息,并且语言没有改变,它保持不变英语(en)。什么可能遗漏的想法?

0 个答案:

没有答案