How to re-translate Django

Hello,

Django comes pre-translated in my language but I don’t like some of phrases. One way to solve this is to edit the django.mo file of the corresponding app (auth for instance), but I assume if I update Django, it will overwrite my edits.

What is the appropriate solution then?

I would outline two different cases:

  1. If the phrases you mention are obviously wrong or suboptimal, I would strongly encourage you to join the Transifex team of your language and fix the affected strings so you and everyone else in your language can benefit of your work… in the spirit of open source.

  2. If this is mostly a matter of personal/project preference, then I guess you have to create your own po/mo files somewhere in your project, add the affected strings with modified translations in those files, and place those files in a location that have higher priority for discovery, as described in Translation | Django documentation | Django

Hope this helps,

Claude

P.S. you should refrain from directly editing .mo files, create/edit .po files and compile them with msgfmt (or using compilemessages management command if the files are discoverable by Django).

Thank you very much.

What I don’t understand is that why I can see this in venv\Lib\site-packages\django\contrib\auth\locale\fa\LC_MESSAGES\django.po:

#: .\venv\Lib\site-packages\django\contrib\auth\base_user.py:59
msgid "password"
msgstr "گذرواژه"

But not in the locale\fa\LC_MESSAGES\django.po when I run python manage.py makemessages -l fa command?

And I do have another question. As you see below, some of permissions of internal models are not translated. How can I translate them?
Screenshot 2024-01-13 165920

[quote=“OmidShojaee, post:3, topic:26683, full:true”]

But not in the locale\fa\LC_MESSAGES\django.po when I run python manage.py makemessages -l fa command?

Because the makemessages command will only extract strings from your project, not the strings from Django built-in code or templates. A trick is for example to create some fake (=unused in your project) files (code or template) in your project where you put the strings you want to re-translate in your own po files.

And I do have another question. As you see below, some of permissions of internal models are not translated. How can I translate them?

This is a known issue: #1688 (Permissions don't get translated in admin interface) – Django

Claude

Would you please elaborate? Let’s say I want to re-translate msgid "Personal info" from django.contrib.auth. How that trick works here?

In one of your apps that have translations, put in one of the files somehting like:

from django.utils.translation import gettext

gettext("Personal info")

So when you run makemessages, this translatable string will appear in your <language>.po file and you can translate it like you want.
Now for your app translations being prioritized over contrib.auth translations, it should appear before it in INSTALLED_APPS. Or you could decide to put your project translations to LOCALE_PATHS (Translation | Django documentation | Django).

Hope this helps,

Claude