Views¶
-
class
i18ntools.views.
SetLanguageView
¶ Available as
set_language()
If you are using
i18n_patterns()
in your URL patterns, theset_language()
view that Django provides won’t work for you. The built-inset_language
view works byactivate()
-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
usesi18ntools.utils.url_for_language()
to transform the URL.SetLanguageView
accepts anext
query string parameter just like the built-in view. If thenext
parameter is not present or invalid,SetLanguageView
will fall back on to theHTTP_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'), )
-