-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add style ordinal/cardinal to NumberFormat (RBNF) #494
Comments
See some good discussion on tc39/proposal-intl-numberformat-v3#22. CC @Bx1 |
Oh this looks great! 😍 new Intl.NumberFormat('en', { style: 'ordinal' }).format(2) // '2nd' Having a built-in web platform way to create the localized strings "1st", "2nd", "3rd" would be amazing. Currently, for English ordinals, using either 1) self-written code with // Option 1: self-written w. Intl.PluralRules() https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/PluralRules
const pr = new Intl.PluralRules("en-US", { type: "ordinal" });
const suffixes = new Map([
["one", "st"],
["two", "nd"],
["few", "rd"],
["other", "th"],
]);
const formatOrdinals = (n) => {
const rule = pr.select(n);
const suffix = suffixes.get(rule);
return `${n}${suffix}`;
};
formatOrdinals(0); // '0th'
formatOrdinals(1); // '1st'
formatOrdinals(2); // '2nd'
formatOrdinals(3); // '3rd' // Option 2: ordinal package https://www.npmjs.com/package/ordinal
import ordinal from 'ordinal';
ordinal(1) // '1st'
ordinal(2) // '2nd'
ordinal(3) // '3rd' I saw that it was accepted by the MessageFormat Working Group in Feb 2024 (but unsure how exactly that interacts with ECMA 402 / any changes to I understand that there is still ICU4X / 402 work to be done. @sffc Maybe for visibility a new issue could be opened in https://github.com/tc39/proposal-intl-numberformat-v3 ? The last one is closed. Or does this need a new |
The MF2 For In other words, supporting MF2 does not require adding ordinal number formatting support to |
TG2 discussion: https://github.com/tc39/ecma402/blob/main/meetings/notes-2024-10-24.md#rbnf Main conclusion: we are likely supportive of adding the decimal ordinal format (1st 2nd 3rd), as well as the small handful of algorithmic numbering systems. There were concerns about adding the spellout style due to the data size. Happy for someone to champion this. |
Support formatting ordinals & cardinals
Style Ordinal
Style Cardinal
The text was updated successfully, but these errors were encountered: