Opened 11 years ago

Closed 11 years ago

#6864 closed (fixed)

JavaScript i18n support can fail for languages with two plural forms

Reported by: Ramiro Morales Owned by: nobody
Component: Internationalization Version: master
Severity: Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


If, as exemplified in the official GNU gettext documentation, the plural form specification headers

"Plural-Forms: nplurals=2; plural=n != 1;\n"


"Plural-Forms: nplurals=2; plural=n>1;\n"

are used instead of

"Plural-Forms: nplurals=2; plural=n != 1 ? 1 : 0;\n"


"Plural-Forms: nplurals=2; plural=n>1 ? 1 : 0;\n"

respectively in a (Django or application) djangojs.po catalog, the ngettext() function fails because the first ones, being C language expressions, rely on the C feature that boolean expressions have to value zero or one. In JavaScript, a boolean in the context of an array index doesn't evaluate to zero or one.

See for the original report by Julien.

This could affect JS i18n for languages that use two-forms pluralization rules, i.e.: Danish, Dutch, English, Faroese, German, Norwegian, Swedish, Estonian, Finnish, Greek, Hebrew, Italian, Portuguese, Spanish, Esperanto, French, Brazilian Portuguese (see the GNU gettext documentation linked above.)

The attached patch modifies the pluralidx() function to work on both scenarios.

Attachments (1)

js-i18n-pluralf.diff (846 bytes) - added by Ramiro Morales 11 years ago.

Download all attachments as: .zip

Change History (4)

Changed 11 years ago by Ramiro Morales

Attachment: js-i18n-pluralf.diff added

comment:1 Changed 11 years ago by Ramiro Morales

Component: UncategorizedInternationalization

comment:2 Changed 11 years ago by Malcolm Tredinnick

Triage Stage: UnreviewedReady for checkin

Thanks, Ramiro. Saved me from having to write this. I agree we need to handle both forms, because the boolean form will be copied from other, similar files.

comment:3 Changed 11 years ago by Malcolm Tredinnick

Resolution: fixed
Status: newclosed

(In [7356]) Fixed #6864 -- Handle Javascript i18n when the plural form expression returns
True or False (so both booleans and integers are allowed). Thanks, Ramiro Morales.

Note: See TracTickets for help on using tickets.
Back to Top