Views

class i18ntools.views.SetLanguageView

Available as set_language()

If you are using i18n_patterns() in your URL patterns, the set_language() view that Django provides won’t work for you. The built-in set_language view works by activate()-ing the language and then returning a redirect back to the exact same URL. However, because the URL contains the language information, LocaleMiddleware will decide to display the page in the old language, not the new language.

Instead of using the activate() function, SetLanguageView changes the language by redirecting the user to the language-prefixed version of that page. SetLanguageView uses i18ntools.utils.url_for_language() to transform the URL.

SetLanguageView accepts a next query string parameter just like the built-in view. If the next parameter is not present or invalid, SetLanguageView will fall back on to the HTTP_REFERER.

url

A fallback URL to redirect to return if neither the next query parameter are present or valid. Defaults to /.

You can use the SetLanguageView by adding it to your URL patterns.

urlpatterns += i18n_patterns('',
    url(r'i18n/$', 'i18ntools.views.set_language', name='set_language'),
  )