Opened 10 months ago
Last modified 6 months ago
#35278 assigned Bug
`ngettext` result can be possibly undefined.
Reported by: | Piotr Kawula | Owned by: | Clara |
---|---|---|---|
Component: | Internationalization | Version: | 5.0 |
Severity: | Normal | Keywords: | ngettext, catalog, i18n, internationalization, |
Cc: | Piotr Kawula, Claude Paroz | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
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.
Change History (8)
comment:1 by , 10 months ago
Description: | modified (diff) |
---|
comment:2 by , 9 months ago
Cc: | added |
---|
comment:4 by , 9 months ago
Triage Stage: | Unreviewed → Accepted |
---|---|
Type: | Uncategorized → Bug |
comment:5 by , 9 months ago
Has patch: | set |
---|---|
Patch needs improvement: | set |
comment:7 by , 6 months ago
Patch needs improvement: | unset |
---|
Patch improved in https://github.com/django/django/pull/18249
comment:8 by , 6 months ago
Patch needs improvement: | set |
---|
We found the tag to execute selenium test --selenium in documentation now, so that was not the issue.
Thank you Piotr for your report.
Claude, would you have an opinion about this report? Thank you!