I’m trying to implement internationalization on my project, but the pages only get translated with the language from settings.LANGUAGE_CODE.
The value of django_language in the user session is correctly set, so is the request header META[HTTP_ACCEPT_LANGUAGE], but the templates are still rendered with the value in LANGUAGE_CODE.
I must use translation.activate(request.session['django_language']) in my views to get the pages translated in the right language.
Is there a way to translate the pages without using translation.activate ?
For information :
- The desired language to translate to is
pt-br, which is in the defaultLANGUAGESset. - If I set
pt-brto theLANGUAGE_CODEthe pages are translated. - The default language must be
en-us. - My locale directory is on the project root.
The locale variables on my settings.py :
LOCALEURL_USE_ACCEPT_LANGUAGE = True
LOCALE_PATHS = (
os.path.join(PROJECT_PATH, 'locale/'),
os.path.join(PROJECT_PATH, '/'),
)
TEMPLATE_CONTEXT_PROCESSORS = (
"django.core.context_processors.i18n",
'django.core.context_processors.request',
)
LANGUAGE_CODE = 'en-us'
USE_I18N = True
USE_L10N = True
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
You need to send
RequestContextas yourcontext_instancefrom your views :