First of all, I am expecting --no-obsolete would comment out msgid and msgstr if gettext is deleted, right?
How I am testing is:
- I wrote
gettext("some string here")in view - I ran
makemessagescommand - It wrote a
.pofile as expected - Then I deleted
gettext()line from view and saved file, verifiedrunserverworking. - I ran
makemessages --no-obsoleteand it has not made any changes to.pofile.
.po file content extract .
#. Translators: This message is a test of wrap line
#: servers/views.py:31
msgid "Do let me know if it works."
msgstr ""
dev environment
Django = 1.11
OS = Mac/Ubuntu 14.04
settings.py
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
LOCALE = (
os.path.join(os.path.dirname(__file__), "locale"),
)
Now with the help of Julien and Tarun, I found following observations.
python manage.py makemessages -l <locale>If there is no
gettextin the file being processed, the above command won'twrite/update.pofile. That means if the corresponding.pofile earlier had entries formsgstrandmsgid, then it won't remove those entries unless file being processed had at least onegettext.Now to make the
--no-obsoletework as expected we need to follow the steps below.First thing run
python manage.py makemessages -l <locale>, this would write.pofile withmsgidandmsgstr.Now set
msgstrand runpython manage.py compilemessages -l <locale>. This command writes.mofile in the same directory as.pofile.Now next time when you run
makemessagesagain (without --no-obsolete),.poand.mofiles are compared and missing/deletedgettextare commented in.pofile.makemessages --no-obsolete, commented entries are removed from the.pofile.E.gif you have 3
gettextentries, and you runmakemessagesfirst time, it would write 3msgidand 3msgstrin.pofile. Now if you remove allgettextentries,.pofile won't be updated after you runmakemessagesagain, but if your keep at least 1gettextentry in same file and runmakemessagesagain, it would delete allmsgidandmsgstrfor deletedgettextentries.But if you run
compilemessagesaftermakemessages,.mofile is created and then for subsequentmakemessagescommands.poand.mofiles are compared and thenmsgidandmsgstris commented in.pofile for deletedgettextentries.Then finally when you run
makemessageswith--no-obsoleteoption the commented messages from.pofiles are deleted permanently.