#29853: Exported jsi18n ngettext() function doesn't check existence of plural
translation before attempting to access it
-------------------------------------+-------------------------------------
Reporter: itsmemohamed | Owner: nobody
Type: Uncategorized | Status: new
Component: | Version: 2.1
Internationalization |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by itsmemohamed:
Old description:
> In https://docs.djangoproject.com/en/2.0/_modules/django/views/i18n/ the
> following exported javascript function
> {{{
> django.ngettext = function(singular, plural, count) {
> var value = django.catalog[singular];
> if (typeof(value) == 'undefined') {
> return (count == 1) ? singular : plural;
> } else {
> return value[django.pluralidx(count)];
> }
> };
> }}}
> doesn't check the existence of {{{value[1]}}} or {{{value[2]}}} before
> attempting to access them if {{{value}}} itself is defined. Therefore
> will return undefined if user attempts to access plural translation, when
> none is defined.
>
> - If user provides no translations at all for singular or plural strings
> it will return formatted un-translated string (Works as expected)
> - If user provides translations for singular and plural strings it will
> return formatted translated string (Works as expected)
> - If user provides singular translation BUT no plural translation it will
> return undefined (Unexpected and extremely difficult to debug)
>
> This function should rather fallback to singular translation OR use un-
> translated plural string in cases where a singular translation is
> provided but no plural translation is provided.
New description:
In https://docs.djangoproject.com/en/2.0/_modules/django/views/i18n/ the
following exported javascript function
{{{
django.ngettext = function(singular, plural, count) {
var value = django.catalog[singular];
if (typeof(value) == 'undefined') {
return (count == 1) ? singular : plural;
} else {
return value[django.pluralidx(count)];
}
};
}}}
doesn't check the existence of {{{value[1]}}} or {{{value[2]}}} before
attempting to access them if {{{value}}} itself is defined. Therefore will
return undefined if user attempts to access plural translation, when none
is defined.
- If user provides no translations at all for singular or plural strings
it will return formatted **un-translated** string (Works as expected)
- If user provides translations for singular and plural strings it will
return formatted **translated** string (Works as expected)
- If user provides singular translation BUT no plural translation it will
return **undefined** (Unexpected and extremely difficult to debug)
This function should rather fallback to singular translation OR use un-
translated plural string in cases where a singular translation is provided
but no plural translation is provided.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/29853#comment:2>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/070.9eaa9f1cb52b6b8632e69f7b121638ff%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.