Change language for django-admin-tools

In my settings.py file, I have:

 LANGUAGE_CODE = 'ru-RU' 

In addition, django-admin-tools are installed and working for me. But the administrator language is still English. What am I doing wrong?

PS.

 $ cat settings.py | grep USE | grep -v USER USE_I18N = True USE_L10N = True USE_TZ = True 
+6
source share
2 answers

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

  • Log in to your normal (non-administrative mode), with superuser / staff privileges and the correct language, and then go to the admin URL.

  • Update admin templates and add a drop-down list to this snippet .

  • Create your own custom middleware to set the language for the administrator:

     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 MIDDLEWARE_CLASSES

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

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

     ADMIN_LANGUAGE_CODE = 'ru-RU' 
+7
source

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

 USE_I18N = True USE_L10N = True 

Also check if you have a translation file ( .mo , .po ) for the Russian language.

0
source

Source: https://habr.com/ru/post/918871/


All Articles