Closed Bug 1610514 Opened 4 years ago Closed 4 years ago

Don't use "percentSign" when unit=percent in Intl.NumberFormat

Categories

(Core :: JavaScript: Internationalization API, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla74
Tracking Status
firefox74 --- fixed

People

(Reporter: anba, Assigned: anba)

Details

Attachments

(3 files)

Per https://tc39.es/proposal-unified-intl-numberformat/section11/numberformat_proposed_out.html#sec-intl.numberformat-internal-slots:

[...] the values within the "percent" field must also contain the substring "{percentSign}"; [...]; and the values within the "unit" field must also contain one of the following substrings: "{unitSymbol}", "{unitNarrowSymbol}", or "{unitName}".

So when style=unit, one of "{unitSymbol}", "{unitNarrowSymbol}", or "{unitName}" must be present. And per https://tc39.es/proposal-unified-intl-numberformat/section11/numberformat_proposed_out.html#sec-partitionnumberpattern, the output must then contain a type=unit element. Contrary to that, we're emitting a type=percentSign element.

js> new Intl.NumberFormat("en-US", { style: "unit", unit: "percent" }).formatToParts(0)
[{type:"integer", value:"0"}, {type:"percentSign", value:"%"}]

Adds a separate FormattedRelativeTimeToParts function to avoid having to add
another one-off argument to the existing intl::FormattedNumberToParts function.

Assignee: nobody → andrebargull
Status: NEW → ASSIGNED

Moving GetFieldTypeForNumberField outside of NumberFormatFields::append let's us
avoid adding another flag to NumberFormatFields in the next part.

Depends on D60966

Pushed by btara@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/4f0bdc386a85
Part 1: Create a separate FormattedRelativeTimeToParts function. r=jwalden
https://hg.mozilla.org/integration/autoland/rev/177fd2d58046
Part 2: Move GetFieldTypeForNumberField out of NumberFormatFields::append. r=jwalden
https://hg.mozilla.org/integration/autoland/rev/236b8297fd5d
Part 3: Pass through a boolean flag to detect style=unit number formatters. r=jwalden
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: