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

This commit is contained in:
Claude Paroz 2019-01-26 16:44:49 +01:00
parent 1e92407f83
commit 16454ac35f
5 changed files with 13 additions and 1 deletions

View File

@ -113,7 +113,7 @@ js_catalog_template = r"""
if (typeof(value) == 'undefined') {
return (count == 1) ? singular : plural;
} 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"
msgstr[0] "%s Resultat"
msgstr[1] "%s Resultate"
msgid "Image"
msgstr "Bild"

View File

@ -30,6 +30,13 @@
</script>
</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">
<script type="text/javascript">
document.write(pgettext("verb", "May"));

View File

@ -435,6 +435,8 @@ class I18nSeleniumTests(SeleniumTestCase):
self.assertEqual(elem.text, "1 Element")
elem = self.selenium.find_element_by_id("ngettext_plur")
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")
self.assertEqual(elem.text, "Kann")
elem = self.selenium.find_element_by_id("npgettext_sing")