summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRamiro Morales <cramm0@gmail.com>2013-06-22 18:39:14 -0300
committerRamiro Morales <cramm0@gmail.com>2013-06-22 18:45:41 -0300
commit1559f84d8b5c2d4d088a27fc0edf02f01a1d65f0 (patch)
treea296ef216910bd294ad74c25d8e9e93e8f9a8402 /tests
parentecf63d5d89c5b511a023a4dcc32a142e1eed97e6 (diff)
Fixed #20311 -- Make sure makemessages doesn't create duplicate Plural-Forms .po file headers.
Thanks naktinis for the report and initial patch.
Diffstat (limited to 'tests')
-rw-r--r--tests/i18n/commands/__init__.py6
-rw-r--r--tests/i18n/commands/extraction.py19
-rw-r--r--tests/i18n/commands/templates/plural.djtpl6
3 files changed, 30 insertions, 1 deletions
diff --git a/tests/i18n/commands/__init__.py b/tests/i18n/commands/__init__.py
index ffd439140e..76249ca34d 100644
--- a/tests/i18n/commands/__init__.py
+++ b/tests/i18n/commands/__init__.py
@@ -1,4 +1,4 @@
-from django.utils.translation import ugettext as _
+from django.utils.translation import ugettext as _, ungettext
# Translators: This comment should be extracted
dummy1 = _("This is a translatable string.")
@@ -6,3 +6,7 @@ dummy1 = _("This is a translatable string.")
# This comment should not be extracted
dummy2 = _("This is another translatable string.")
+# This file has a literal with plural forms. When processed first, makemessages
+# shouldn't create a .po file with duplicate `Plural-Forms` headers
+number = 3
+dummuy3 = ungettext("%(number)s Foo", "%(number)s Foos", number) % {'number': number}
diff --git a/tests/i18n/commands/extraction.py b/tests/i18n/commands/extraction.py
index 8696ae453b..dd1dce2ed0 100644
--- a/tests/i18n/commands/extraction.py
+++ b/tests/i18n/commands/extraction.py
@@ -329,6 +329,15 @@ class SymlinkExtractorTests(ExtractorTests):
class CopyPluralFormsExtractorTests(ExtractorTests):
+ PO_FILE_ES = 'locale/es/LC_MESSAGES/django.po'
+
+ def tearDown(self):
+ os.chdir(self.test_dir)
+ try:
+ self._rmrf('locale/es')
+ except OSError:
+ pass
+ os.chdir(self._cwd)
def test_copy_plural_forms(self):
os.chdir(self.test_dir)
@@ -338,6 +347,16 @@ class CopyPluralFormsExtractorTests(ExtractorTests):
po_contents = force_text(fp.read())
self.assertTrue('Plural-Forms: nplurals=2; plural=(n != 1)' in po_contents)
+ def test_override_plural_forms(self):
+ """Ticket #20311."""
+ os.chdir(self.test_dir)
+ management.call_command('makemessages', locale='es', extensions=['djtpl'], verbosity=0)
+ self.assertTrue(os.path.exists(self.PO_FILE_ES))
+ with open(self.PO_FILE_ES, 'r') as fp:
+ po_contents = force_text(fp.read())
+ found = re.findall(r'^(?P<value>"Plural-Forms.+?\\n")\s*$', po_contents, re.MULTILINE | re.DOTALL)
+ self.assertEqual(1, len(found))
+
class NoWrapExtractorTests(ExtractorTests):
diff --git a/tests/i18n/commands/templates/plural.djtpl b/tests/i18n/commands/templates/plural.djtpl
new file mode 100644
index 0000000000..b2f2a18750
--- /dev/null
+++ b/tests/i18n/commands/templates/plural.djtpl
@@ -0,0 +1,6 @@
+{% load i18n %}
+{% comment %}
+This file has a literal with plural forms. When processed first, makemessages
+shouldn't create a .po file with duplicate `Plural-Forms` headers
+{% endcomment %}
+{% blocktrans count number=3 %}{{ number }} Bar{% plural %}{{ number }} Bars{% endblocktrans %}