-
-
Notifications
You must be signed in to change notification settings - Fork 35
Design document for percent formatting #1068
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
base: main
Are you sure you want to change the base?
Conversation
This document is focused for now on documenting the options.
exploration/percent-format.md
Outdated
Note that the selector selects on the scaled value | ||
(selectors currently cannot select fractional parts) |
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.
Highlighting for @sffc and @ryzokuken that this may require supporting something like style
as an Intl.PluralRules option, or being ok with Intl.MessageFormat offering a capability beyond Intl.PluralRules.
Is plural category selection on percent-formatted values already well supported by the ICU libraries?
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.
Also, if selection makes sense for :number style=percent
, is there a reason to not allow selection for :unit unit=percent
as well? And if the latter is fine, then why not allow selection for all of :unit
.
My preference would be for us to not allow for selection with percent formatting at this time.
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 may require supporting something like style as an Intl.PluralRules option
I don't think this necessarily follows? The function handler would scale the value before using plural rules, just as the function handler calls Intl.NumberFormat
to format the number later.
My preference would be for us to not allow for selection with percent formatting at this time.
This would require a separate placeholder just to perform message selection on what is fundamentally a 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 may require supporting something like style as an Intl.PluralRules option
I don't think this necessarily follows? The function handler would scale the value before using plural rules, just as the function handler calls
Intl.NumberFormat
to format the number later.
Quite recently in tc39/ecma402#989 we added notation
as one of the Intl.PluralRules
options. It would therefore be a bit surprising to effectively support style=percent
for selection scaling in Intl.MessageFormat, but not for Intl.PluralRules
.
My preference would be for us to not allow for selection with percent formatting at this time.
This would require a separate placeholder just to perform message selection on what is fundamentally a number.
Does your position generalise to preferring selection to work on all :unit
values?
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.
Does your position generalise to preferring selection to work on all :unit values?
I'm not sure. I think it might, at least in terms of exact selection. Plural rules don't work well/aren't needed (what's actually wanted is more like inflection). But there are plenty of cases where one might want a specific value to produce a specific message, with 0
being the most common case.
A lot of unit selection cases actually look like what ChoiceFormat
is good at: separating messages above/below a given threshold, e.g. switching from kilometers to meters (or miles to feet) in driving directions at some cutoff.
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 happy with the Proposed Design: Let's not add the style
option back to :number
. It was productive when we removed it, and I don't want to go back. Among other things, it causes problems when mixed with other options, questionable plural selection behavior as @eemeli noted, and inconsistent with Intl.NumberFormat which uses style
for currency and unit as well.
I also do not like requiring :unit unit=percent
, because we want percent formatting to not pull in all unit formatting data, but this is unavoidable in this design for reasons the ICU4X TC has expressed previously.
|
||
## Constraints | ||
|
||
_What prior decisions and existing conditions limit the possible design?_ |
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 we should mention that since MF1 scales, we want MF2 to be able to scale?
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 don't necessarily want MF2 to scale. There is a hot debate about whether scaling or non-scaling is preferred.
(chair hat OFF) Adding
I'm not opposed to adding convenience functions. I think Alternatively we could regard
I think My preferred solution is:
(chair hat ON) I observe that we're not closing on a design. If we do not achieve consensus on a design in the next (2025-06-02) call, I will call for a ballot. |
I talked with @sffc while we met in person this past week, and it came up that ICU4X would almost certainly want unit formatting to be separated by category. As in, when formatting a value that includes its own unit (say, If that is a requirement that we accept, then it suggests to me that we ought to include the category in the function name, so we'd have e.g. |
@eemeli suggested:
So The "requirement" is really a dodge around creating separate functions for each unit or around creating a single function whose data loading depends on an option (or on the operand value). Most implementations bind the unit data late, but we should allow for ICU4X and its need/desire to bind the data early. |
I disagree completely. By "category" I assume what is meant is "quantity" (from SI, with a few other special cases). See https://www.unicode.org/cldr/charts/48/supplemental/unit_conversions.html There are downsides of the mentioned approach (unit formatting to be separated by category)
So I don't think it is at all justified to jump through hoops by requiring categories. Note: the heading at the top of the chart needs some tweaks. For example, it doesn't mention beaufort, which has a more complex conversion than just factor & offset. |
The current design of @eemeli's suggestion of There are many quantities, but I would be happy enough splitting out the most important ones and throwing everything else into |
I looked at #1006 and didn't find a discussion of unit. I am strongly opposed to requiring quantities with unit ids. What might work is for unit is to only require a small subset of unit ids to be supported. Then ICU4X and other memory-limited implementations could choose to only support the required set. But that is really a separate issue. |
Co-authored-by: Tim Chevalier <tjc@igalia.com>
Co-authored-by: Tim Chevalier <tjc@igalia.com>
We did not take too close of a look at |
I'm spinning off the |
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.
As discussed on today's call, I've moved the proposed solution to be one of the alternatives under consideration.
The intent with this change is to allow us to land this PR, and to iterate further from there. As discussed today, adding a separate :percent
function might be the least worst option here, and it would match what we're doing with unit and currency formatting.
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 like landing this with all the alternatives listed as alternatives and not taking a position on which one we want to pick.
Co-authored-by: Shane F. Carr <sffc@google.com>
This document now includes the proposed design discussed in the (poorly documented, sparsely attended) 2025-05-19 call. The emerging consensus appears to be:
:number
/:integer
with optionstyle=percent
(this is the current design) with scaling:unit
with unitpercent
is REQUIRED but other units are not required, this function has NO scalingThe most recent commit posits that
:number
/:integer
select after scaling because we don't support fraction selection currently.Note
All previous conversations were marked resolved on purpose and not because their content was in any way deficient, off topic, or necessarily addressed. Please comment on the proposed design.