TIMEX
TIMEX

Reputation: 272164

Django LocaleMiddleware determines the language for me. How do I know what language it determined?

I need to know what language it returns, so that I can perform my own actions.

Upvotes: 1

Views: 413

Answers (2)

user324541
user324541

Reputation: 19

templates with RequestContext have {{ LANGUAGE_CODE }} by default. http://docs.djangoproject.com/en/dev/topics/i18n/internationalization/#other-tags

Upvotes: 1

KillianDS
KillianDS

Reputation: 17186

from django.utils import translation

def myview(...):
    ...
    lang = translation.get_language()
    ...

This will return the language code used in the current thread, so in your case, that set by the middleware.

Upvotes: 6

Related Questions