summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTushar <30565750+tushar5526@users.noreply.github.com>2023-07-14 01:39:53 +0530
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-07-14 08:47:30 +0200
commit88a2de3c3906f5acc14bb68e98c128fc13f2f1ae (patch)
treed91081f89467ea21f64a914c519b87969a23aa8f
parent02966a30dd31d2b9d35f8c481a448b9bf377895e (diff)
Fixed #34448 -- Doc'd and tested --no-obsolete option of makemessages.
Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
-rw-r--r--docs/ref/django-admin.txt4
-rw-r--r--tests/i18n/obsolete_translations/__init__.py5
-rw-r--r--tests/i18n/obsolete_translations/locale/de/LC_MESSAGES/django.po26
-rw-r--r--tests/i18n/test_extraction.py16
4 files changed, 51 insertions, 0 deletions
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 <EMAIL@ADDRESS>, 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 <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\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"