diff --git a/docs/ref/django-admin.txt b/docs/ref/django-admin.txt index a46910f9f3..9e13db435a 100644 --- a/docs/ref/django-admin.txt +++ b/docs/ref/django-admin.txt @@ -677,6 +677,10 @@ is: Requires ``gettext`` 0.19 or newer. +.. django-admin-option:: --no-obsolete + +Removes obsolete message strings from the ``.po`` files. + .. django-admin-option:: --keep-pot Prevents deleting the temporary ``.pot`` files generated before creating the diff --git a/tests/i18n/obsolete_translations/__init__.py b/tests/i18n/obsolete_translations/__init__.py new file mode 100644 index 0000000000..3c69a69a26 --- /dev/null +++ b/tests/i18n/obsolete_translations/__init__.py @@ -0,0 +1,5 @@ +from django.utils.translation import gettext as _ + +string1 = _("This is a translatable string.") +# Obsolete string. +# string2 = _("Obsolete string.") diff --git a/tests/i18n/obsolete_translations/locale/de/LC_MESSAGES/django.po b/tests/i18n/obsolete_translations/locale/de/LC_MESSAGES/django.po new file mode 100644 index 0000000000..613191865f --- /dev/null +++ b/tests/i18n/obsolete_translations/locale/de/LC_MESSAGES/django.po @@ -0,0 +1,26 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2023-07-14 01:04+0530\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: __init__.py:3 +msgid "This is a translatable string." +msgstr "This is a translated string." + +#~ msgid "Obsolete string." +#~ msgstr "Translated obsolete string." diff --git a/tests/i18n/test_extraction.py b/tests/i18n/test_extraction.py index ab73596c4a..9e10218666 100644 --- a/tests/i18n/test_extraction.py +++ b/tests/i18n/test_extraction.py @@ -868,6 +868,22 @@ class LocationCommentsTests(ExtractorTests): ) +class NoObsoleteExtractorTests(ExtractorTests): + work_subdir = "obsolete_translations" + + def test_no_obsolete(self): + management.call_command( + "makemessages", locale=[LOCALE], verbosity=0, no_obsolete=True + ) + self.assertIs(os.path.exists(self.PO_FILE), True) + with open(self.PO_FILE) as fp: + po_contents = fp.read() + self.assertNotIn('#~ msgid "Obsolete string."', po_contents) + self.assertNotIn('#~ msgstr "Translated obsolete string."', po_contents) + self.assertMsgId("This is a translatable string.", po_contents) + self.assertMsgStr("This is a translated string.", po_contents) + + class KeepPotFileExtractorTests(ExtractorTests): POT_FILE = "locale/django.pot"