How Django determines the current language

Django comes with a middleware that determines the current language based on request data. This is the LocaleMiddleware middleware that resides in django.middleware.locale. LocaleMiddleware performs the following tasks:

  1. If you are using i18_patterns, that is, you use translated URL patterns, it looks for a language prefix in the requested URL to determine the current language.
  2. If no language prefix is found, it looks for an existing LANGUAGE_SESSION_KEY in the current user's session.
  3. If the language is not set in the session, it looks for an existing cookie with the current language. A custom name for this cookie can be provided in the LANGUAGE_COOKIE_NAME setting. By default, the name for this cookie is django_language.
  4. If no cookie is found, it looks for the Accept-Language HTTP header of the request.
  5. If the Accept-Language header does not specify a language, Django uses the language defined in the LANGUAGE_CODE setting.

By default, Django will use the language defined in the LANGUAGE_CODE setting unless you are using LocaleMiddleware. The process described here only applies when using this middleware.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.103.204