Opened 4 years ago
Closed 4 years ago
#33068 closed Bug (invalid)
makemessages is inconvenient when overriding default django translations
| Reported by: | Satyajeet Kanetkar | Owned by: | nobody |
|---|---|---|---|
| Component: | Internationalization | Version: | 3.2 |
| Severity: | Normal | Keywords: | makemessages |
| Cc: | Claude Paroz | Triage Stage: | Unreviewed |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
By default, makemessages will remove/comment out translations from the BASE_DIR / "locale/<locale>/LC_MESSAGES/django.po file if a msgid is not used anywhere in the project.
This makes it very inconvenient to override the default django translations. Here's a very simple example:
django/conf/locale/mr/LC_MESSAGES/django.po has:
#: utils/dates.py:6 msgid "Monday" msgstr ""
I override this in BASE_DIR / "locale/mr/LC_MESSAGES/django.po" with:
msgid "Monday" msgstr "सोमवार"
And this works fine; until someone else comes along and runs ./manage.py makemessages -l mr, causing the above translation which is used, to be commented out!
#~ msgid "Monday" #~ msgstr "सोमवार"
I feel that makemessages should not delete/comment translations that are overriding default django translations, otherwise the utility of that command is severely reduced.
A current workaround is to explicitly copy over all strings that are overriden into a file in the project so that gettext can pick them up, but it creates unnecessary boilerplate.
A possible solution could be to change the makemessages command to also scan the django source code, in addition to the app's source, although I am not sure of the complications here.
In addition, the documentation could also be improved by adding a recommended way of overriding the default translations that ship with django, that works well with the makemessages command.
Change History (5)
comment:1 by , 4 years ago
| Summary: | makemessages is useless when overriding default django translations → makemessages is inconvenient when overriding default django translations |
|---|
comment:2 by , 4 years ago
| Cc: | added |
|---|---|
| Resolution: | → worksforme |
| Status: | new → closed |
comment:3 by , 4 years ago
@Mariusz Felisiak Thanks for the attempt at reproducing, but one additional step is needed to make the bug re appear.
Before running compilemessages/makemessages you need to add at least one custom translation so that gettext actually has reason to modify the .po file.
Simplest would be to add the below snippet at the end of the urls.py of the default scaffolding:
from django.utils.translation import gettext as _
_("Translate This!")
And then run the makemessages and compilemessages steps as mentioned. You should see the legitimate translations getting commented out.
I will be re-opening the ticket as I am able to reproduce this with the above minimal code added to a default django project.
comment:4 by , 4 years ago
| Resolution: | worksforme |
|---|---|
| Status: | closed → new |
comment:5 by , 4 years ago
| Resolution: | → invalid |
|---|---|
| Status: | new → closed |
Thanks for extra details. You should copy base translations to the separate directory if you want to include your own translations, and override base translations in your project, i.e.
- copy
django/conf/locale/mr/LC_MESSAGES/django.poto the<BASE_DIR>/django/conf/locale/mr/LC_MESSAGES/django.po(override base translations), <BASE_DIR>/locale/mr/LC_MESSAGES/django.powill contain your own project translations,
Thanks for the report, however I cannot reproduce this issue with following steps:
django/conf/locale/mr/LC_MESSAGES/django.poto the<BASE_DIR>/locale/mr/LC_MESSAGES/django.poLOCALE_PATHS = [BASE_DIR / 'locale']to settings<BASE_DIR>/locale/mr/LC_MESSAGES/django.popython manage.py makemessages -l mrI don't see any lines commented in the
<BASE_DIR>/locale/mr/LC_MESSAGES/django.po.