Django provides two mechanisms to internationalize URL patterns:
Adding the language prefix to the root of the URL patterns to make it possible for
LocaleMiddleware
to detect the language to activate from the requested URL.Making URL patterns themselves translatable via the
django.utils.translation.ugettext_lazy()
function.
Using either one of these features requires that an active language be set for each request; in other words, you need to have django.middleware.locale.LocaleMiddleware
in your MIDDLEWARE_CLASSES
setting.
This function can be used in your root URLconf and Django will automatically prepend the current active language code to all URL patterns defined within i18n_patterns()
. Example URL patterns:
from django.conf.urls import include, url from django.conf.urls.i18n import i18n_patterns from about import views as about_views from news import views as news_views from sitemap.views import...