#35278: `ngettext` result can be possibly undefined.
-------------------------------------+-------------------------------------
     Reporter:  Piotr Kawula         |                    Owner:  Piotr
                                     |  Kawula
         Type:  Uncategorized        |                   Status:  assigned
    Component:                       |                  Version:  5.0
  Internationalization               |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
  ngettext,catalog,i18n,internationalization,|  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Description changed by Piotr Kawula:

Old description:

> When the translation engine provide an invalid plural rule the
> `pluralidx` function can return invalid index which will cause the
> `ngettext` to return value that does not exist - `undefined`.
> Same result can occur when the `newcatalog` contains invalid values, for
> example:
>
> {{{
> const newcatalog = {
>   '%s something': [],
>   ...
> }
> }}}
>
> And in `ngettext` we have:
> {{{
> django.ngettext = function(singular, plural, count) {
>  const value = django.catalog[singular];
>  if (typeof value === 'undefined') {
>     return (count == 1) ? singular : plural;
>   } else {
>     return value.constructor === Array ? value[django.pluralidx(count)] :
> value;
>   }
> };
> }}}
>
> Which in case of empty array go for `value[django.pluralidx(count)] `
> which is undefined.
>

> I think we want the `ngettext` function to return string always, if it
> does not find proper value in catalog, should default to the provided
> values.

New description:

 When the translation engine provide an invalid plural rule the `pluralidx`
 function can return invalid index which will cause the `ngettext` to
 return value that does not exist - `undefined`.
 Same result can occur when the `newcatalog` contains invalid values, for
 example:

 {{{
 const newcatalog = {
   '%s something': [],
   ...
 }
 }}}

 And in `ngettext` we have:
 {{{
 django.ngettext = function(singular, plural, count) {
  const value = django.catalog[singular];
  if (typeof value === 'undefined') {
     return (count == 1) ? singular : plural;
   } else {
     return value.constructor === Array ? value[django.pluralidx(count)] :
 value;
   }
 };
 }}}

 Which in case of empty array go for `value[django.pluralidx(count)] `
 which is undefined.


 I think we want the `ngettext` function to return string always, if it
 does not find proper value in catalog, should default to the provided
 values.

 It affects the previous versions too.

--
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35278#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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018e1803998b-fe4328be-a762-4c93-aaf9-d4b592921159-000000%40eu-central-1.amazonses.com.

Reply via email to