Skip to content

Fix plural forms for locales like Brazilian Portuguese - #74

Open
cpruijsen wants to merge 1 commit into
alexanderwallin:masterfrom
cpruijsen:fix/issue-70
Open

cpruijsen wants to merge 1 commit into
alexanderwallin:masterfrom
cpruijsen:fix/issue-70

Conversation

@cpruijsen

Copy link
Copy Markdown

ngettext now looks up a locale-specific plural form before the
language code, so pt_BR uses n > 1 instead of Portuguese n != 1.
The old path used the language code only (pt_BRpt), so count 0
took the plural msgstr. Fixes #70.

Lookup is the normalized full locale (pt-BR / pt_BRpt_br), then
Gettext.getLanguageCode as before. lib/plurals.js gains a pt_br
entry with n > 1. pt is unchanged.

Hyphen and underscore are both accepted because this repo's README
uses BCP 47 hyphens (sv-SE) while gettext and the issue use pt_BR.

The formulas match the issue and GNU gettext's plural table
(ptn != 1, pt_BRn > 1), and the Translation Project
pt_BR.po header (Plural-Forms: nplurals=2; plural=(n > 1);).
GNU's table has no other regional exception.

Decision

Locale-then-language lookup, with pt_br as n > 1 and pt left as
n !== 1. Treating pt as Brazilian (CLDR) and adding pt_PT for
European Portuguese would change existing pt callers. Happy to switch
to the CLDR mapping if you prefer.

Did not evaluate headers['plural-forms'] from catalogs. The library
already ignores that header, and compiling it is the GHSA-g974-hxvm-x689
shape (#72).

Test plan

  • npx mocha test/gettext-test.js
    - 31 / 32: 0 and 1 → singular, 2 → plural
    - 33: 0 → plural, 1 → singular, 2 → plural
    - 34 still falls back to 35 (36)
  • npx grunt (jshint + mocha)

Look up a locale-specific plural function before falling back to the
language code so pt_BR uses n > 1 instead of Portuguese n != 1.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong plural form for e.g. Brazilian Portuguese

1 participant