diff --git a/django/views/i18n.py b/django/views/i18n.py index c8cc5d043f..c3a813b0fe 100644 --- a/django/views/i18n.py +++ b/django/views/i18n.py @@ -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): diff --git a/docs/releases/1.10.5.txt b/docs/releases/1.10.5.txt index ac9270c3c0..381f956bc8 100644 --- a/docs/releases/1.10.5.txt +++ b/docs/releases/1.10.5.txt @@ -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`). diff --git a/tests/view_tests/locale/pt/LC_MESSAGES/djangojs.mo b/tests/view_tests/locale/pt/LC_MESSAGES/djangojs.mo new file mode 100644 index 0000000000..8407e242fc Binary files /dev/null and b/tests/view_tests/locale/pt/LC_MESSAGES/djangojs.mo differ diff --git a/tests/view_tests/locale/pt/LC_MESSAGES/djangojs.po b/tests/view_tests/locale/pt/LC_MESSAGES/djangojs.po new file mode 100644 index 0000000000..ca643162e9 --- /dev/null +++ b/tests/view_tests/locale/pt/LC_MESSAGES/djangojs.po @@ -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 , 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 \n" +"Language-Team: LANGUAGE \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" diff --git a/tests/view_tests/locale/ru/LC_MESSAGES/djangojs.mo b/tests/view_tests/locale/ru/LC_MESSAGES/djangojs.mo index 21659a93d3..cb0a8d10db 100644 Binary files a/tests/view_tests/locale/ru/LC_MESSAGES/djangojs.mo and b/tests/view_tests/locale/ru/LC_MESSAGES/djangojs.mo differ diff --git a/tests/view_tests/locale/ru/LC_MESSAGES/djangojs.po b/tests/view_tests/locale/ru/LC_MESSAGES/djangojs.po index 4ea193a880..e9eda86192 100644 --- a/tests/view_tests/locale/ru/LC_MESSAGES/djangojs.po +++ b/tests/view_tests/locale/ru/LC_MESSAGES/djangojs.po @@ -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" diff --git a/tests/view_tests/tests/test_i18n.py b/tests/view_tests/tests/test_i18n.py index 4778b5dd37..bde0ad42d4 100644 --- a/tests/view_tests/tests/test_i18n.py +++ b/tests/view_tests/tests/test_i18n.py @@ -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/') diff --git a/tests/view_tests/tests/test_i18n_deprecated.py b/tests/view_tests/tests/test_i18n_deprecated.py index 88ce57f47a..e60a04ad01 100644 --- a/tests/view_tests/tests/test_i18n_deprecated.py +++ b/tests/view_tests/tests/test_i18n_deprecated.py @@ -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/')