Change locale for django-admin-tools
Asked Answered
G

2

6

In my settings.py file I have:

LANGUAGE_CODE = 'ru-RU'

also, I have installed and working django-admin-tools. But admin language still english. What I'm doing wrong?

PS.

$ cat settings.py | grep USE | grep -v USER
USE_I18N = True
USE_L10N = True
USE_TZ = True
Garmaise answered 24/6, 2012 at 12:10 Comment(0)
A
9

You need to set the language specifically for the admin app. Since django does not provide a language drop down as part of the default login, you have a few options:

  1. Login to your normal (non admin view), with superuser/staff credentials and the correct language, then shift over to the admin URL.

  2. Update the admin templates and add a language dropdown see this snippet.

  3. Create some custom middleware to set the language for admin:

    from django.conf import settings
    from django.utils import translation
    
    class AdminLocaleMiddleware:
    
        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
    

    Add it to your MIDDLEWARE_CLASSES

    MIDDLEWARE_CLASSES = {
        # ...
        'foo.bar.AdminLocaleMiddleware',
        # ...
    }
    

    Set the language you want for the admin in settings.py:

    ADMIN_LANGUAGE_CODE = 'ru-RU'
    
Askew answered 24/6, 2012 at 13:24 Comment(1)
Hi, thanks for the answer. I'm trying your [3] and I can't manage to include the Middleware, where do you place the file?Buddybuderus
L
0

Check if you have translation and localization enabled in your settings.py:

USE_I18N = True
USE_L10N = True

Also check if you have the translation file (.mo, .po) for russian.

Lorrianelorrie answered 24/6, 2012 at 12:14 Comment(1)
Yes, I'm has these lines. .mo and .po files exists in site-packages.Garmaise

© 2022 - 2024 — McMap. All rights reserved.