7

How can I translate the application label in the Django CMS admin?

See the screenshot:

Screenshot

Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
Nikolay Georgiev
  • 1,047
  • 1
  • 12
  • 22

5 Answers5

33

UPDATE: For Django 3+ import gettext_lazy instead of ugettext_lazy. Like this:

from django.utils.translation import gettext_lazy as _

OK. I have found how to translate the app name without changing the database name. Example (inside apps.py of app you want to translate):

from django.apps import AppConfig
from django.utils.translation import ugettext_lazy as _

class MyAppConfig(AppConfig):
    name = 'MyApp'
    verbose_name = _('Transalation of MyApp here')

Run makemessages -a and after altering django.po run compilemessages and you are done. Hit refresh in admin and your app name is translated.

David Wolf
  • 1,400
  • 1
  • 9
  • 18
nik_m
  • 11,825
  • 4
  • 43
  • 57
  • 1
    While this works sometimes, it doesn't all the time. I'm having a problem where only SOME of my app names are getting translated, and even though I have a verbose name assigned, it still doesn't get translated in the site. I have five apps in my project and three of them are not translating. – Nathan Oct 07 '18 at 03:08
  • @Nathan. Hm... I think you should make a new question and show some code. Otherwise it'll be difficult to help you from the comments section! – nik_m Oct 07 '18 at 09:29
  • 3
    @Nathan You are probably missing `default_app_config = 'myapp.apps.MyAppConfig'` in your `__init__.py` – dmcontador Jul 08 '19 at 11:17
  • @dmcontador I figured it out, but this was quit ea long time ago and i forgot what I did to fix it! ha – Nathan Aug 05 '19 at 00:25
  • You still need to add the app to INSTALLED_APPS using the AppConfig class: ``` INSTALLED_APPS = [ ... 'MyApp.apps.MyAppConfig' ... ] ``` – Aldian Fazrihady Aug 14 '19 at 03:36
  • 1
    "ugettext_lazy" should be "gettext_lazy" – tinyhare Feb 17 '22 at 06:27
4

It might too late to answer this question but i am sharing my experience.

Add below mention code to model.py

VERBOSE_NAME = _('Appname')

After the use this

django-admin.py makemessages -a
django-admin.py compilemessages

This will add entry to django.po.

Vishnu
  • 3,899
  • 2
  • 18
  • 19
2

The answer below was correct for Django 1.4 or 1.5, I believe. For more modern answer, see https://stackoverflow.com/a/32431808/1067717


Have a look at this previously asked question on the similar topic for internationalization in Django.

Internally, it uses Model._meta.app_label to display the application name. Inspect admin view and its template for further information.

Seyeong Jeong
  • 10,658
  • 2
  • 28
  • 39
0

I don't know which CMS you used,so I just give you a sample code below. Maybe you can change the fields in your models.py file like this:

class Entry(models.Model):
    title         = models.CharField(u'标题',max_length=300)

    # other fields here

pic

The code above is work well in my project(django 1.4.2),the first param(string) in CharField() will display in my Admin view,I think it is useful for you.

The full code in my project:https://github.com/tianyu0915/pythoner.net/blob/master/pythoner/wiki/models.py#L69

Yohn
  • 866
  • 8
  • 11
0

I use Django 4.2.1 and for example, you can translate an application label by adding verbose_name to MyAppConfig class in my_app/apps.py as shown below. *You should use gettext_lazy() instead of gettext() otherwise there is an error and you can see my answer explaining how to translate in Django:

# "my_app/apps.py"

from django.apps import AppConfig
from django.utils.translation import gettext_lazy as _

class MyAppConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'my_app'
    verbose_name = _('my_app') # Here

Then, my_app is translated to nom_app in French in yellow as shown below. *I don't know how to translate the model label persons in blue:

enter image description here

Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129