Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ngettextnow looks up a locale-specific plural form before thelanguage code, so
pt_BRusesn > 1instead of Portuguesen != 1.The old path used the language code only (
pt_BR→pt), so count 0took the plural msgstr. Fixes #70.
Lookup is the normalized full locale (
pt-BR/pt_BR→pt_br), thenGettext.getLanguageCodeas before.lib/plurals.jsgains apt_brentry with
n > 1.ptis unchanged.Hyphen and underscore are both accepted because this repo's README
uses BCP 47 hyphens (
sv-SE) while gettext and the issue usept_BR.The formulas match the issue and GNU gettext's plural table
(
pt→n != 1,pt_BR→n > 1), and the Translation Projectpt_BR.poheader (Plural-Forms: nplurals=2; plural=(n > 1);).GNU's table has no other regional exception.
Decision
Locale-then-language lookup, with
pt_brasn > 1andptleft asn !== 1. Treatingptas Brazilian (CLDR) and addingpt_PTforEuropean Portuguese would change existing
ptcallers. Happy to switchto the CLDR mapping if you prefer.
Did not evaluate
headers['plural-forms']from catalogs. The libraryalready 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)