Django: Change or translate the app name in the admin menu

Posted by ads' corner on Tuesday, 2020-12-01
Posted in [Django]

Let’s say I have a Django app users. The admin menu shows this as category Users. That’s ok, but if the website users speak another language I want this name translated. Also I’m not necessarily using Users as name in the admin menu as section name, but can use something more descriptive. Website Users, as example.

Rename the section

Renaming the section name in the admin menu is easy to do. Open the apps.py file and add one line to the Meta class:

1
verbose_name = "Website Users"

The whole file should look similar to:

1
2
3
4
5
from django.apps import AppConfig

class UsersConfig(AppConfig):
    name = 'users'
    verbose_name = 'Website Users'

Translate the name

Using a translated name is a bit more work, because the entire Django translation framework must be in place. That’s necessary to do anyway if you want to provide translations in your website, and is not part of this blog posting.

Once the framework is activated, all what’s necessary is importing the translation module, use a translated string, and provide a translation:

1
2
3
4
5
6
from django.apps import AppConfig
from django.utils.translation import gettext_lazy as _

class UsersConfig(AppConfig):
    name = 'users'
    verbose_name = _('Website Users')

After updating the translations with makemessages and compiling the translations with compilemessages the admin website will start using your translation as section name.


Categories: [Django]