-
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
Design for currency and unit inputs that carry their values #911
Comments
@sffc: in the constructor of what? A currency value should carry its currency code (and not just a number) around. A unit amount should likewise not forget it's unit. |
Currently one needs to set the currency or unit in the constructor of |
For context, the MF2 spec currently includes this for its
To accommodate this and still allow e.g. currency formatting, the Intl.MessageFormat proposal's This allows for usage like: const msg = new Intl.MessageFormat('en', 'Your total is {$price :number style=currency}')
const price = { valueOf: () => 42, options: { currency: 'EUR' } }
msg.format({ price }) // 'Your total is €42.00' This kinda works, and seems like the least worst option at the moment. But it still feels somewhat hacky, esp. as it doesn't differentiate options like It might be better to have some more explicit representation of number+currency and number+unit that could be supported also outside Intl.MessageFormat, in Intl.NumberFormat. |
Rather than setting the unit/currency in the constructor, should it also be carried in the type being formatted?
Might be wanted by Intl.MessageFormat.
CC @eemeli
The text was updated successfully, but these errors were encountered: