-
-
Notifications
You must be signed in to change notification settings - Fork 36
Improved Currency Support #27
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
Comments
ICU MessageFormat supports this via number skeletons:
|
What if the currency code needs to be set dynamically? |
In Fluent we solve it with partially formatted variables: https://projectfluent.org/fluent/guide/functions.html bundle.format_pattern(pattern, {
amount: FluentNumber(num, { currency: "USD" }),
});
or:
|
what's important is that we blacklist ECMA402 NumberFormat option |
Exactly the right thing to do: Nobody wants to see an amount in Japanese Yen but then be charged in US$. |
Having to declare the currency within the string itself means you have to know the currency you're dealing with in advance. - which is often not the case. |
+1. Probably if the localizer needs to set the currency, it would be some sort of static text (terms of use) and would not require to use such functionalities. Regarding the syntax itself, I know we are not here to discuss this part yet, but I do like the idea of having a But one thing I have noticed is while Unicode tried to define currencies and their formats, if you browse around the web, it's hard to find any consistency on that front. |
Prices and currency values are pretty important to us at Amazon. So we have invested in building currency data types, our own price formatter classes/functions across a number of programming languages, and integrating the price formatter into message format. Declaring the currency in the formatter, as noted by @MickMonaghan, @duerst, and others is the wrong design. The currency belongs with the value. Our formatter instead focuses on different use cases: standalone, in sentence, compact (no decimal portion, smaller symbol where possible), "legal" (i.e. showing the ISO currency code), etc---that is, conveying the intention of the developer to save (many many) lines of configuring code. We also have a bunch of features related to "format to parts" type functionality (what field order is used, what fields are present, whether there is a space between the symbol and value, etc.). I'm excited by @sffc's work on number skeletons. I was reluctant to use subformat keywords in our implementation because the history of subformats is that they become restrictive, outmoded, and thus not so useful. The difference between our keywords and the short/medium/long/full ones is that ours are tied to specific consistent uses, rather than arbitrary cases (what does |
Google has a Money type which is used in many instances, and it would be good if this support was able to align in some way or be extensible with this type. |
For Siri, it has been the following options and things to consider.
Things that aren't good to have inside a message.
What has never been needed is to assume that the currency is related to the language or region setting. That would be a bad design choice. The currency should be known by the developer before hand, much like the time zone needs to be known by the developer before hand. |
Given various developments, this appears like it might fit into the discussion of default registry entries. |
As mentioned in today's telecon (2023-09-18), closing old requirements issues. If necessary, open new issues (in this case against the default registry) |
Is your feature request related to a problem? Please describe.
Currency and its format is already documented to some extent by Unicode but to my knowledge, MessageFormat support is not as simple as the date or number arguments.
Describe the solution you'd like
I would like to see easier to use currency support that is closer to date or number arguments (see example below).
Describe why your solution should shape the standard
Currency is a very common scenario and providing an out of the box, easy to use solution would bring more value and reasons to use the syntax.
Additional context or examples
It would expect to have either scenario as input:
The output would be:
The output would be:
Also having an extensive choice of format for both numbers and the currency sign would be a must to give full flexibility. Maybe the format could also be overwritten in the input?
The text was updated successfully, but these errors were encountered: