0

I'm trying to translate the entire Django Admin from English to French.

This is my django-project below. *I use Django 4.2.1:

django-project
 |-core
 |  |-settings.py
 |  └-urls.py
 |-my_app1
 |  |-models.py
 |  |-admin.py
 |  └-apps.py
 |-my_app2
 └-locale
    └-fr
       └-LC_MESSAGES
          |-django.po
          └-django.mo

And, this is core/settings.py below:

# "core/settings.py"

MIDDLEWARE = [
    ...
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.locale.LocaleMiddleware',
    'django.middleware.common.CommonMiddleware',
    ...
]

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True

from django.utils.translation import gettext_lazy as _

LANGUAGES = (
    ('en', _('English')),
    ('fr', _('French'))
)

And, this is core/urls.py below:

# "core/urls.py"

from django.contrib import admin
from django.urls import path
from django.conf.urls.i18n import i18n_patterns

urlpatterns = i18n_patterns(
    path('admin/', admin.site.urls)
)

And, this is my_app1/models.py below:

# "my_app1/models.py"

from django.db import models
from django.utils.translation import gettext_lazy as _

class Person(models.Model):
    name = models.CharField(max_length=20, verbose_name=_("name"))

    class Meta:
        verbose_name = _('person')
        verbose_name_plural = _('persons')

And, this is my_app1/apps.py below:

# "my_app1/apps.py"

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

class MyApp1Config(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'my_app1'
    verbose_name = _('my_app1')

And, this is locale/fr/LC_MESSAGES/django.po below:

# "locale/fr/LC_MESSAGES/django.po"

...

#: .\core\settings.py:140
msgid "English"
msgstr "Anglais"

#: .\core\settings.py:141
msgid "French"
msgstr "Français"

#: .\my_app1\apps.py:7
msgid "my_app1"
msgstr "mon_app1"

#: .\my_app1\models.py:6
msgid "name"
msgstr "nom"

#: .\my_app1\models.py:12
#, fuzzy
msgid "person"
msgstr "personne"

#: .\my_app1\models.py:13
#, fuzzy
msgid "persons"
msgstr "personnes"

...

But, only the model label person is not translated at http://localhost:8000/fr/admin/my_app1/person/add/ as shown below:

enter image description here

So, how can I translate the model label person?

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

1 Answers1

0

You should comment #, fuzzy out by adding one more # to the front or completely remove them in locale/fr/LC_MESSAGES/django.po as shown below:

# "locale/fr/LC_MESSAGES/django.po"

...

#: .\core\settings.py:140
msgid "English"
msgstr "Anglais"

#: .\core\settings.py:141
msgid "French"
msgstr "Français"

#: .\my_app1\apps.py:7
msgid "my_app1"
msgstr "mon_app1"

#: .\my_app1\models.py:6
msgid "name"
msgstr "nom"

#: .\my_app1\models.py:12
##, fuzzy # <- Here
msgid "person"
msgstr "personne"

#: .\my_app1\models.py:13
##, fuzzy # <- Here
msgid "persons"
msgstr "personnes"

...

Then, run the command below:

django-admin compilemessages

Now, http://localhost:8000/fr/admin/my_app1/person/add/ can also translate the model label person as shown below:

enter image description here

In addition, fuzzy is explained in the doc as shown below:

fuzzy

This flag can be generated by the msgmerge program or it can be inserted by the translator herself. It shows that the msgstr string might not be a correct translation (anymore). Only the translator can judge if the translation requires further modification, or is acceptable as is. Once satisfied with the translation, she then removes this fuzzy attribute. The msgmerge program inserts this when it combined the msgid and msgstr entries after fuzzy search only. See Fuzzy Entries.

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