[Answered ]-Django translation doesn't work although dgango_language cookie is set

1๐Ÿ‘

As django docs say, 'django.middleware.locale.LocaleMiddleware' should be placed between "django.contrib.sessions.middleware.SessionMiddleware" and "django.middleware.common.CommonMiddleware",

It should come after SessionMiddleware, because LocaleMiddleware makes use of session data. And it should come before CommonMiddleware because CommonMiddleware needs an activated language in order to resolve the requested URL.

So your MIDDLEWARE setting should look like this:

MIDDLEWARE = [        
    "django.middleware.security.SecurityMiddleware",        
    "django.contrib.sessions.middleware.SessionMiddleware",        
    'django.middleware.locale.LocaleMiddleware',        
    "django.middleware.common.CommonMiddleware",        
    "django.middleware.csrf.CsrfViewMiddleware",        
    "django.contrib.auth.middleware.AuthenticationMiddleware",        
    "django.contrib.messages.middleware.MessageMiddleware",        
    "django.middleware.clickjacking.XFrameOptionsMiddleware"        
]

0๐Ÿ‘

What version of Django do you use? The trans HTML template tag seems not in use any more, in 4.x docs translate is the name of the tag in the examples.

Iโ€™d also check this too, just in case it has anything to do with the Accept-Language HTTP header.

Leave a comment