Open
Description
Time and time again, programmers are confused about how to use Intl.PluralRules, especially in ways that relate to rendered digits, like how to take the plural form of 1
versus 1.00
versus 1K
.
In the ICU implementation, to solve this problem, we allow users to pass a FormattedNumber, the output of NumberFormatter, into PluralRules.
Here's a draft of how this could look in ECMAScript:
const fmt = new Intl.NumberFormat("fr-FR", {
notation: "compact"
});
const { string, pluralForm } = fmt.formatSelect(2.5e6);
console.log(string, pluralForm);
// "2.5 M" many
Intl.PluralRules would still be useful for the case where you don't care about the rendered output, but the new API on Intl.NumberFormat would help clarify how to get the effective plural form for a formatted number.
The new APIs:
formatSelect
returns{ string, pluralForm }
formatToPartsSelect
(orformatSelectToParts
) returns{ parts, pluralForm }
Thoughts?
Metadata
Metadata
Assignees
Type
Projects
Status