Opened 3 years ago

Closed 3 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 Satyajeet Kanetkar, 3 years ago

Summary: makemessages is useless when overriding default django translationsmakemessages is inconvenient when overriding default django translations

comment:2 by Mariusz Felisiak, 3 years ago

Cc: Claude Paroz added
Resolution: worksforme
Status: newclosed

Thanks for the report, however I cannot reproduce this issue with following steps:

  • create new project
  • copy django/conf/locale/mr/LC_MESSAGES/django.po to the <BASE_DIR>/locale/mr/LC_MESSAGES/django.po
  • add LOCALE_PATHS = [BASE_DIR / 'locale'] to settings
  • translate some strings in <BASE_DIR>/locale/mr/LC_MESSAGES/django.po
  • compile messages,
  • call python manage.py makemessages -l mr

I don't see any lines commented in the <BASE_DIR>/locale/mr/LC_MESSAGES/django.po.

comment:3 by Satyajeet Kanetkar, 3 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.

Version 0, edited 3 years ago by Satyajeet Kanetkar (next)

comment:4 by Satyajeet Kanetkar, 3 years ago

Resolution: worksforme
Status: closednew

comment:5 by Mariusz Felisiak, 3 years ago

Resolution: invalid
Status: newclosed

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.po to the <BASE_DIR>/django/conf/locale/mr/LC_MESSAGES/django.po (override base translations),
  • <BASE_DIR>/locale/mr/LC_MESSAGES/django.po will contain your own project translations,

see How Django discovers translations.

Note: See TracTickets for help on using tickets.
Back to Top