Fixed #27418 -- Fixed occasional missing plural forms in JavaScriptCatalog.

This commit is contained in:
Waldemar Kornewald 2016-12-09 15:07:25 +01:00 committed by Tim Graham
parent 1e629928e9
commit b24af2f405
8 changed files with 69 additions and 2 deletions

View File

@ -253,7 +253,7 @@ def get_javascript_catalog(locale, domain, packages):
else:
raise TypeError(key)
for k, v in pdict.items():
catalog[k] = [v.get(i, '') for i in range(maxcnts[msgid] + 1)]
catalog[k] = [v.get(i, '') for i in range(maxcnts[k] + 1)]
return catalog, plural
@ -401,7 +401,7 @@ class JavaScriptCatalog(View):
else:
raise TypeError(key)
for k, v in pdict.items():
catalog[k] = [v.get(i, '') for i in range(maxcnts[msgid] + 1)]
catalog[k] = [v.get(i, '') for i in range(maxcnts[k] + 1)]
return catalog
def get_context_data(self, **kwargs):

View File

@ -11,3 +11,6 @@ Bugfixes
* Fixed a crash in the debug view if ``request.user`` can't be retrieved, such
as if the database is unavailable (:ticket:`27567`).
* Fixed occasional missing plural forms in ``JavaScriptCatalog``
(:ticket:`27418`).

Binary file not shown.

View File

@ -0,0 +1,27 @@
# 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: 2007-09-15 19:15+0200\n"
"PO-Revision-Date: 2010-05-12 12:41-0300\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
msgid "{count} plural2"
msgid_plural "{count} plural2s"
msgstr[0] "{count} plural2"
msgstr[1] "{count} plural2s"
msgid "{count} plural3"
msgid_plural "{count} plural3s"
msgstr[0] "{count} plural3"
msgstr[1] "{count} plural3s"

View File

@ -22,3 +22,16 @@ msgstr "перевод"
msgid "Choose a time"
msgstr "Выберите время"
msgid "{count} plural2"
msgid_plural "{count} plural2s"
msgstr[0] ""
msgstr[1] ""
msgstr[2] ""
msgid "{count} plural3"
msgid_plural "{count} plural3s"
msgstr[0] "{count} plural3 p3"
msgstr[1] "{count} plural3 p3s"
msgstr[2] "{count} plural3 p3t"

View File

@ -314,6 +314,18 @@ class JsI18NTests(SimpleTestCase):
self.assertContains(response, 'il faut le traduire')
self.assertNotContains(response, "Untranslated string")
def test_i18n_fallback_language_plural(self):
"""
The fallback to a language with less plural forms maintains the real
language's number of plural forms.
"""
with self.settings(LANGUAGE_CODE='pt'), override('ru'):
response = self.client.get('/jsi18n/')
self.assertEqual(
response.context['catalog']['{count} plural3'],
['{count} plural3', '{count} plural3s', '{count} plural3 p3t']
)
def test_i18n_english_variant(self):
with override('en-gb'):
response = self.client.get('/jsi18n/')

View File

@ -95,6 +95,18 @@ class JsI18NTests(SimpleTestCase):
self.assertContains(response, 'il faut le traduire')
self.assertNotContains(response, "Untranslated string")
def test_i18n_fallback_language_plural(self):
"""
The fallback to a language with less plural forms maintains the real
language's number of plural forms.
"""
with self.settings(LANGUAGE_CODE='pt'), override('ru'):
response = self.client.get('/jsi18n/')
self.assertEqual(
response.context['catalog']['{count} plural3'],
['{count} plural3', '{count} plural3s', '{count} plural3 p3t']
)
def test_i18n_english_variant(self):
with override('en-gb'):
response = self.client.get('/old_jsi18n/')