Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #20311 -- Make sure makemessages doesn't create duplicate Plura…

…l-Forms .po file headers.

Thanks naktinis for the report and initial patch.
  • Loading branch information...
commit 1559f84d8b5c2d4d088a27fc0edf02f01a1d65f0 1 parent ecf63d5
Ramiro Morales ramiro authored
6 django/core/management/commands/makemessages.py
View
@@ -402,11 +402,11 @@ def copy_plural_forms(self, msgs, locale):
if self.verbosity > 1:
self.stdout.write("copying plural forms: %s\n" % m.group('value'))
lines = []
- seen = False
+ found = False
for line in msgs.split('\n'):
- if not line and not seen:
+ if not found and (not line or plural_forms_re.search(line)):
line = '%s\n' % m.group('value')
- seen = True
+ found = True
lines.append(line)
msgs = '\n'.join(lines)
break
6 tests/i18n/commands/__init__.py
View
@@ -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 @@
# 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}
19 tests/i18n/commands/extraction.py
View
@@ -329,6 +329,15 @@ def test_symlink(self):
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 @@ def test_copy_plural_forms(self):
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):
6 tests/i18n/commands/templates/plural.djtpl
View
@@ -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 %}
Please sign in to comment.
Something went wrong with that request. Please try again.