The LocaleMiddleware
is responsible for determining what language the browser should be served; it is consistently picking en
for your browser, and you need to figure out why.
See How Django discovers language preference for the details, but the short order is:
- look at the path prefix; for
/
and/dimension/
there isn't one yet. - look for a
_language
key in the session (falling back todjango_language
for backwards compatibility). - look for a
django_language
cookie (or whatever you set insettings.LANGUAGE_COOKIE_NAME
) - look at the browser
Accept-Language
header - use
settings.LANGUAGE_CODE
.
Note that nothing sets the session key or cookie explicitly; your own code needs to do so. You can use the set_language()
redirect view to do this for you; a form in your web UI would POST to that view to let a visitor set a different language.
You can also set the session key or cookie explicitly when a visitor comes to /fr/
and doesn't yet have an explicit cookie or session key. You'd do so in a view attached to ^$
in the i18n_patterns()
url map (which is called for any /<language_code>/
request), instead of the redirect you have now. That view can still redirect, of course.
Even without explicitly setting the cookie, your redirect should at the very least use the request.LANGUAGE_CODE
variable:
url(r'^$', lambda r: redirect('/{}/dimension/'.format(r.LANGUAGE_CODE)), name="home"),