#29825: ngettext returns invalid result if msgstr is also a valid msgid in the 
same
catalog
-------------------------------------+-------------------------------------
     Reporter:  jeremy-moffitt       |                    Owner:  nobody
         Type:  Uncategorized        |                   Status:  new
    Component:  Uncategorized        |                  Version:  2.1
     Severity:  Normal               |               Resolution:
     Keywords:  ngettext             |             Triage Stage:
  localization                       |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Description changed by jeremy-moffitt:

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...
>
>     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

--

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29825#comment:1>
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/072.2b9ba3083ef8e897f03e0b602448652b%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to