#35278: `ngettext` result can be possibly undefined.
-------------------------------------+-------------------------------------
               Reporter:  Piotr      |          Owner:  Piotr Kawula
  Kawula                             |
                   Type:             |         Status:  assigned
  Uncategorized                      |
              Component:             |        Version:  5.0
  Internationalization               |       Keywords:
               Severity:  Normal     |  
ngettext,catalog,i18n,internationalization,
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 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.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35278>
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/0107018e1802ac97-da9cedfb-9ea4-4e88-a746-ef903a324deb-000000%40eu-central-1.amazonses.com.

Reply via email to