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