Now with the help of Julien and Tarun, I found following observations.
python manage.py makemessages -l <locale>
If there is no gettext
in the file being processed, the above command won't write/update
.po
file. That means if the corresponding .po
file earlier had entries for msgstr
and msgid
, then it won't remove those entries unless file being processed had at least one gettext
.
Note: Above behavior is irrespective of --no-obsolete
Now to make the --no-obsolete
work as expected we need to follow the steps below.
First thing run python manage.py makemessages -l <locale>
, this would write .po
file with msgid
and msgstr
.
Now set msgstr
and run python manage.py compilemessages -l <locale>
. This command writes .mo
file in the same directory as .po
file.
Now next time when you run makemessages
again (without --no-obsolete), .po
and .mo
files are compared and missing/deleted gettext
are commented in .po
file.
- And when you run
makemessages --no-obsolete
, commented entries are removed from the .po
file.
E.g
if you have 3 gettext
entries, and you run makemessages
first time, it would write 3 msgid
and 3 msgstr
in .po
file. Now if you remove all gettext
entries, .po
file won't be updated after you run makemessages
again, but if your keep at least 1 gettext
entry in same file and run makemessages
again, it would delete all msgid
and msgstr
for deleted gettext
entries.
But if you run compilemessages
after makemessages
, .mo
file is created and then for subsequent makemessages
commands .po
and .mo
files are compared and then msgid
and msgstr
is commented in .po
file for deleted gettext
entries.
Then finally when you run makemessages
with --no-obsolete
option the commented messages from .po
files are deleted permanently.
settings.py
file? – Maculate