Nov 12

Django set language for admin

Middleware that intialize specific locale for admin pages.

If you want to explicitly set language for django admin section use this middleware:

from django.conf import settings
from django.utils import translation


class AdminLocaleURLMiddleware:

    def process_request(self, request):
        if request.path.startswith('/admin'):
            request.LANG = getattr(settings, 'ADMIN_LANGUAGE_CODE', settings.LANGUAGE_CODE)
            translation.activate(request.LANG)
            request.LANGUAGE_CODE = request.LANG

Then put somewhere in settings.py:

ADMIN_LANGUAGE_CODE=’it’

and add middleware:

MIDDLEWARE_CLASSES = (
   ...
    'utils.multilang.middleware.AdminLocaleURLMiddleware',
   ....