[2.2.x] Fixed #29825 -- Fixed JS ngettext if the string is a non-plural msgid in the catalog.

Backport of 16454ac35f from master.
This commit is contained in:
Claude Paroz 2019-01-26 16:44:49 +01:00 committed by Tim Graham
parent 728358c5cf
commit caaa01142d
5 changed files with 13 additions and 1 deletions

View File

@ -113,7 +113,7 @@ js_catalog_template = r"""
if (typeof(value) == 'undefined') { if (typeof(value) == 'undefined') {
return (count == 1) ? singular : plural; return (count == 1) ? singular : plural;
} else { } else {
return value[django.pluralidx(count)]; return value.constructor === Array ? value[django.pluralidx(count)] : value;
} }
}; };

View File

@ -39,3 +39,6 @@ msgid "%s result"
msgid_plural "%s results" msgid_plural "%s results"
msgstr[0] "%s Resultat" msgstr[0] "%s Resultat"
msgstr[1] "%s Resultate" msgstr[1] "%s Resultate"
msgid "Image"
msgstr "Bild"

View File

@ -30,6 +30,13 @@
</script> </script>
</p> </p>
<p id="ngettext_onnonplural">
<!-- The po file only contains the non plural "Image" string. -->
<script type="text/javascript">
document.write(interpolate(ngettext("Image", "Images", 5), [1]));
</script>
</p>
<p id="pgettext"> <p id="pgettext">
<script type="text/javascript"> <script type="text/javascript">
document.write(pgettext("verb", "May")); document.write(pgettext("verb", "May"));

View File

@ -435,6 +435,8 @@ class I18nSeleniumTests(SeleniumTestCase):
self.assertEqual(elem.text, "1 Element") self.assertEqual(elem.text, "1 Element")
elem = self.selenium.find_element_by_id("ngettext_plur") elem = self.selenium.find_element_by_id("ngettext_plur")
self.assertEqual(elem.text, "455 Elemente") self.assertEqual(elem.text, "455 Elemente")
elem = self.selenium.find_element_by_id("ngettext_onnonplural")
self.assertEqual(elem.text, "Bild")
elem = self.selenium.find_element_by_id("pgettext") elem = self.selenium.find_element_by_id("pgettext")
self.assertEqual(elem.text, "Kann") self.assertEqual(elem.text, "Kann")
elem = self.selenium.find_element_by_id("npgettext_sing") elem = self.selenium.find_element_by_id("npgettext_sing")