Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change locale for django-admin-tools

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
like image 511
Drakmail Avatar asked Jun 24 '12 12:06

Drakmail


People also ask

How do I change the admin style in Django?

Sometimes you can just extend the original admin file and then overwrite a block like {% block extrastyle %}{% endblock %} in django/contrib/admin/templates/admin/base. html as an example. If your style is model specific you can add additional styles via the Media meta class in your admin.py .

What is Gettext_lazy Django?

Its used for translation for creating translation files like this: # app/locale/cs/LC_MESSAGES/django.po #: templates/app/index.html:3 msgid "email address" msgstr "emailová adresa" Than it can be rendered in template as translated text.

How do I get admin access to Django?

If needed, run the Django app again with python manage.py runserver 0.0. 0.0:8000 and then navigate once more to the URL http:// your-server-ip :8000/admin/ to get to the admin login page. Then log in with the username and password and password you just created.


1 Answers

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'
    
like image 164
Burhan Khalid Avatar answered Sep 22 '22 19:09

Burhan Khalid