From 8f0842ab522b238bf3aacd4d6bab2c6d384469bf Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Wed, 10 Mar 2021 10:18:07 -0400 Subject: use Intl.PluralRules for better num pluralization --- upd8.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'upd8.js') diff --git a/upd8.js b/upd8.js index a54a886..97ee8bf 100755 --- a/upd8.js +++ b/upd8.js @@ -494,6 +494,10 @@ function genStrings(stringsJSON, defaultJSON = null) { conjunction: new Intl.ListFormat(code, {type: 'conjunction'}), disjunction: new Intl.ListFormat(code, {type: 'disjunction'}), unit: new Intl.ListFormat(code, {type: 'unit'}) + }, + plural: { + cardinal: new Intl.PluralRules(code, {type: 'cardinal'}), + ordinal: new Intl.PluralRules(code, {type: 'ordinal'}) } }; @@ -523,9 +527,7 @@ function genStrings(stringsJSON, defaultJSON = null) { const countHelper = (stringKey, argName = stringKey) => (value, {strings, unit = false}) => strings( (unit - ? `count.${stringKey}.withUnit` + (value === 1 - ? '.singular' - : '.plural') + ? `count.${stringKey}.withUnit.` + strings.intl.plural.cardinal.select(value) : `count.${stringKey}`), {[argName]: strings.intl.number.format(value)}); @@ -568,7 +570,7 @@ const count = { }, index: (value, {strings}) => { - return strings('count.index', {index: value}); + return strings('count.index.' + strings.intl.plural.ordinal.select(value), {index: value}); }, number: value => strings.intl.number.format(value), -- cgit 1.3.0-6-gf8a5