-
-
Notifications
You must be signed in to change notification settings - Fork 34
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
Define currency & unit formatting #908
base: main
Are you sure you want to change the base?
Conversation
Should have a warning that it is better to support currencies with a composite input parameter. (The same will go for units of measure, eventually.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this isn't the approach I would prefer. I think breaking off :currency
and unit
as optional functions is the better long term course. It not only encourages the right behavior, but it keeps implementers from having to make sense of {$x :number style=currency notation=scientific}
and other oddities. I also find that there are options one wants to have for currencies or units that are different from those found in the number formatter and which require a great deal of fiddling with options to get right.
For example, the currency JPY
renders differently in sentence contexts vs. standalone in the Japanese locale:
symbol=¥1,235 sentence=1,235 円
I appreciate getting the PR for review. I've added this to the agenda for Monday (although without your presence, we might not be able to close it--put thoughts here on in 838??)
Except where indicated otherwise, | ||
the following options and their values are | ||
REQUIRED to be available on the function `:number`: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, some option values are optional, but none of the options are. This reads in a kind of chewy way. Perhaps:
Except where indicated otherwise, | |
the following options and their values are | |
REQUIRED to be available on the function `:number`: | |
The following _options_ MUST be available on the function `:number`. | |
Except where marked `OPTIONAL`, _option_ values MUST be available | |
on the function `:number`: |
- `currency` (OPTIONAL, see [Currency Formatting](#currency-formatting) below) | ||
- `unit` (OPTIONAL, see [Unit Formatting](#unit-formatting) below) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my comment on 838, I suggested that we might want to break these into separate functions. There is a certain appeal to that, particularly since the options interact and since we want to encourage structured monetary and unit types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eh, that probably works for me too. What about percent formatting? Should that have its own function as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think percent is fine where it is? It's more like scientific or other presentational gorp for formatting a pure number (you never really see a Percent
type walking about). I could be convinced otherwise, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do also apply this transform to percentage values:
message-format-wg/spec/registry.md
Lines 220 to 221 in 4ea56e4
When implementing `style=percent`, the numeric value of the _operand_ | |
MUST be multiplied by 100 for the purposes of formatting. |
If there's reason enough to define :unit
and :currency
, it would make it much easier to also define :percent
, and not allow any of these to be used as operands.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The transformation for percents is multiplying a number/moving the radix. It doesn't require changing the type or any external data. We could add a per-mille formattnig too and @macchiati has proposed adding offset
. These are all pure number things, which is why I'd keep them together with :number
/:integer
.
Units and currencies have a host of specialized options and accept different types. That's why I'd separate them: they are only numbers because they contain numeric values and want to select like numbers.
I wouldn't object to providing a :percent
function. I don't think it is required that we do so, obviously. But maybe we do it for consistency?
- `standard` (default) | ||
|
||
If an implementation supports currency formatting, | ||
it MAY make the following option available on the function `:number` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be optional for implementation for the reasons I cited in #838. Best practices are cool, but users should not be require to box up currency values in their legacy applications.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that I understand your comment here. Do you mean that we ought to require all implementations to support an option specifying a currency code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, but if you support style=currency
then you must support the currency
option. This says MAY.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see why such a requirement ought to be placed on all implementations that support currency formatting. I agree with @macchiati in #838 (comment) that this can be solved in user-space instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be solved in the user space. Users are encouraged to do so.
But my experience is that there are many applications that are mono-currency or which provide the currency contextually (at the document/record/transaction level). I see these people who are somewhere along the internationalization curve and it is a hard sell to get them to refactor their application just to format a number as a currency.
There are many runtime environments in which there is no currency value class/object/structure built-in: people have invented their own. Providing a way for these applications to work reasonably I think is important too.
But, finally, I think the key thing is that our functions/option sets should be as portable as possible. It simplifies the work for tools and editors and the learning curve of developers. Where we have optional functionality, the package should be as consistent as possible. Implementations can extend it, but those options will (we hope) be namespaced.
Co-authored-by: Addison Phillips <[email protected]>
I agree with Addison on making currency/units into separate functions. |
Closes #838
Adds definitions for
style=currency
andstyle=unit
as OPTIONAL for:number
.Support for compound operand values SHOULD be provided, and the corresponding
currency
andunit
options MAY be provided.Note that "currency formatting" and "unit formatting" are each treated as distinct optional blocks, so that e.g. supporting
currencyDisplay
but not supportingcurrencySign
is not valid.MUSTard is clarified.
The
style
option is removed from:integer
, for clarity. All functionality for integral formatting with different styles is still supported via:number
, but an:integer
is made more explicitly just that, an integer.Removes one of the few remaining spec mentions recommending readers "to track development [...] during Tech Preview".