#29825: ngettext returns invalid result if msgstr is also a valid msgid in the
same
catalog
-------------------------------------+-------------------------------------
Reporter: Jeremy Moffitt | Owner: nobody
Type: Bug | Status: new
Component: | Version: 2.1
Internationalization |
Severity: Normal | Resolution:
Keywords: ngettext | Triage Stage: Accepted
localization |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):
* stage: Unreviewed => Accepted
Old description:
> 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...
>
> {{{#!python
> 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.catalog["Image"] 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
New description:
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...
{{{#!python
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.catalog["Image"]` 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
--
Comment:
Tentatively accepting for investigation.
--
Ticket URL: <https://code.djangoproject.com/ticket/29825#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/072.d323c39b6757d10d125813d5bb14fcca%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.