Fixed #20311 -- Make sure makemessages doesn't create duplicate Plural-Forms .po file headers.
Thanks naktinis for the report and initial patch.
This commit is contained in:
parent
ecf63d5d89
commit
1559f84d8b
|
@ -402,11 +402,11 @@ class Command(NoArgsCommand):
|
||||||
if self.verbosity > 1:
|
if self.verbosity > 1:
|
||||||
self.stdout.write("copying plural forms: %s\n" % m.group('value'))
|
self.stdout.write("copying plural forms: %s\n" % m.group('value'))
|
||||||
lines = []
|
lines = []
|
||||||
seen = False
|
found = False
|
||||||
for line in msgs.split('\n'):
|
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')
|
line = '%s\n' % m.group('value')
|
||||||
seen = True
|
found = True
|
||||||
lines.append(line)
|
lines.append(line)
|
||||||
msgs = '\n'.join(lines)
|
msgs = '\n'.join(lines)
|
||||||
break
|
break
|
||||||
|
|
|
@ -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
|
# Translators: This comment should be extracted
|
||||||
dummy1 = _("This is a translatable string.")
|
dummy1 = _("This is a translatable string.")
|
||||||
|
@ -6,3 +6,7 @@ dummy1 = _("This is a translatable string.")
|
||||||
# This comment should not be extracted
|
# This comment should not be extracted
|
||||||
dummy2 = _("This is another translatable string.")
|
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}
|
||||||
|
|
|
@ -329,6 +329,15 @@ class SymlinkExtractorTests(ExtractorTests):
|
||||||
|
|
||||||
|
|
||||||
class CopyPluralFormsExtractorTests(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):
|
def test_copy_plural_forms(self):
|
||||||
os.chdir(self.test_dir)
|
os.chdir(self.test_dir)
|
||||||
|
@ -338,6 +347,16 @@ class CopyPluralFormsExtractorTests(ExtractorTests):
|
||||||
po_contents = force_text(fp.read())
|
po_contents = force_text(fp.read())
|
||||||
self.assertTrue('Plural-Forms: nplurals=2; plural=(n != 1)' in po_contents)
|
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):
|
class NoWrapExtractorTests(ExtractorTests):
|
||||||
|
|
||||||
|
|
|
@ -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 %}
|
Loading…
Reference in New Issue