Marcus Lima
Marcus Lima

Reputation: 13

Can't get my pages translated without changing `settings.LANGUAGE_CODE' in Django

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 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',    
)

Upvotes: 1

Views: 407

Answers (1)

Burhan Khalid
Burhan Khalid

Reputation: 174662

You need to send RequestContext as your context_instance from your views :

return render_to_response('hello.html',
                          context_instance=RequestContext(request))

Upvotes: 1

Related Questions