私は Django 1.6 を使用していますが、何かが欠けているように感じますが、Cookie は現在選択されている言語に設定されていますが、表示言語はデフォルトのままです。
対応コード:
設定.py
LANGUAGES = (
('hu', 'Hungarian'),
('en', 'English'),
)
TEMPLATE_CONTEXT_PROCESSORS = (
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.static",
"django.core.context_processors.tz",
"django.contrib.messages.context_processors.messages",
"django.core.context_processors.request"
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware'
)
LANGUAGE_CODE = 'en-US'
TIME_ZONE = 'CET'
USE_I18N = True
USE_L10N = True
USE_TZ = True
urls.py
urlpatterns = patterns('',
url(r'^i18n/', include('django.conf.urls.i18n')),
...
)
テンプレート
{% extends 'base.html' %}
{% load i18n %}
...
<h4>{% trans "Modern Technologies" %}</h4>
...
makemessages -aを実行して lang ファイルを作成し、rosetta をインストールして言語を編集しました。次に、compilemessagesを実行しました。Chrome で Cookie「django_language」が正しく設定されていることを確認します。ただし、実際のテキストはデフォルトの「Modern Technologies」のままです。