Opened 6 years ago
Last modified 6 years ago
#29825 closed Bug
ngettext returns invalid result if msgstr is also a valid msgid in the same catalog — at Version 1
Description (last modified by ) ¶
When ngettext is called with a msgid and that msgid has a msgstr that is also a valid msgid in the same catalog, the return value is not the msgstr, but instead is a single character from the msgstr. The problem seems to be that the msgstr is passed back into ngettext and since it has a valid value in the catalog, the code breaks into the else block and returns the 0 index character...
django.ngettext = function(singular, plural, count) { var value = django.catalog[singular]; if (typeof(value) == 'undefined') { return (count == 1) ? singular : plural; } else { return value[django.pluralidx(count)]; } };
The example in OpenStack Horizon (see link below) is that the French bundle contains the following:
msgid "Image"
msgstr "Image"
This should return "Image" ... instead it returns "I" ... the result of django.catalogImage being "Image" , which then breaks into the else block of the following if statement, resulting in a return value of "Image"[0] ... or the capital letter "I". For languages where the msgstr does not match a valid key in the file, this problem does not occur.
see also openstack bug: https://bugs.launchpad.net/horizon/+bug/1778189