[Django] #35278: `ngettext` result can be possibly undefined.

15 views
Skip to first unread message

Django

unread,
Mar 7, 2024, 3:23:36 AM3/7/24
to django-...@googlegroups.com
#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.

Django

unread,
Mar 7, 2024, 3:24:38 AM3/7/24
to django-...@googlegroups.com
#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

unread,
Mar 8, 2024, 8:01:56 PM3/8/24
to django-...@googlegroups.com
#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
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

* cc: Claude Paroz (added)

Comment:

Thank you Piotr for your report.

Claude, would you have an opinion about this report? Thank you!
--
Ticket URL: <https://code.djangoproject.com/ticket/35278#comment:2>

Django

unread,
Mar 11, 2024, 9:26:55 AM3/11/24
to django-...@googlegroups.com
#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
-------------------------------------+-------------------------------------
Comment (by Natalia Bidart):

Tentatively accepting.
--
Ticket URL: <https://code.djangoproject.com/ticket/35278#comment:3>

Django

unread,
Mar 11, 2024, 9:27:12 AM3/11/24
to django-...@googlegroups.com
#35278: `ngettext` result can be possibly undefined.
-------------------------------------+-------------------------------------
Reporter: Piotr Kawula | Owner: Piotr
| Kawula
Type: Bug | Status: assigned
Component: | Version: 5.0
Internationalization |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
ngettext,catalog,i18n,internationalization,|
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

* stage: Unreviewed => Accepted
* type: Uncategorized => Bug

--
Ticket URL: <https://code.djangoproject.com/ticket/35278#comment:4>

Django

unread,
Mar 16, 2024, 12:07:46 PM3/16/24
to django-...@googlegroups.com
#35278: `ngettext` result can be possibly undefined.
-------------------------------------+-------------------------------------
Reporter: Piotr Kawula | Owner: Piotr
| Kawula
Type: Bug | Status: assigned
Component: | Version: 5.0
Internationalization |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
ngettext,catalog,i18n,internationalization,|
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Claude Paroz):

* has_patch: 0 => 1
* needs_better_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/35278#comment:5>

Django

unread,
Jun 8, 2024, 9:28:28 AM6/8/24
to django-...@googlegroups.com
#35278: `ngettext` result can be possibly undefined.
-------------------------------------+-------------------------------------
Reporter: Piotr Kawula | Owner: Clara
Type: Bug | Status: assigned
Component: | Version: 5.0
Internationalization |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
ngettext,catalog,i18n,internationalization,|
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Clara):

* owner: Piotr Kawula => Clara

Comment:

Getting the ticket to fix the test problem.
--
Ticket URL: <https://code.djangoproject.com/ticket/35278#comment:6>

Django

unread,
Jun 8, 2024, 9:41:11 AM6/8/24
to django-...@googlegroups.com
#35278: `ngettext` result can be possibly undefined.
-------------------------------------+-------------------------------------
Reporter: Piotr Kawula | Owner: Clara
Type: Bug | Status: assigned
Component: | Version: 5.0
Internationalization |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
ngettext,catalog,i18n,internationalization,|
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Clara):

* needs_better_patch: 1 => 0

Comment:

Patch improved in https://github.com/django/django/pull/18249
--
Ticket URL: <https://code.djangoproject.com/ticket/35278#comment:7>

Django

unread,
Jun 8, 2024, 10:28:48 AM6/8/24
to django-...@googlegroups.com
#35278: `ngettext` result can be possibly undefined.
-------------------------------------+-------------------------------------
Reporter: Piotr Kawula | Owner: Clara
Type: Bug | Status: assigned
Component: | Version: 5.0
Internationalization |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
ngettext,catalog,i18n,internationalization,|
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Clara):

* needs_better_patch: 0 => 1

Comment:

We found the tag to execute selenium test --selenium in documentation now,
so that was not the issue.
--
Ticket URL: <https://code.djangoproject.com/ticket/35278#comment:8>
Reply all
Reply to author
Forward
0 new messages