diff options
author | (quasar) nebula <towerofnix@gmail.com> | 2021-03-10 10:18:07 -0400 |
---|---|---|
committer | (quasar) nebula <towerofnix@gmail.com> | 2021-03-10 10:18:07 -0400 |
commit | 8f0842ab522b238bf3aacd4d6bab2c6d384469bf (patch) | |
tree | 1b611eec7c671ea3f7a316caca15671afe05e102 /upd8.js | |
parent | c21054c17e5736299434d4aa9b0729b757e982fa (diff) |
use Intl.PluralRules for better num pluralization
Diffstat (limited to 'upd8.js')
-rwxr-xr-x | upd8.js | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/upd8.js b/upd8.js index a54a8867..97ee8bf7 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), |