Skip to content
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

fix(@formatjs/intl-numberformat): determine plurality using rounded number value #2065

Merged
merged 1 commit into from
Sep 7, 2020

Conversation

pyrocat101
Copy link
Member

In earlier implementation of ES2020 Intl.NumberFormat shipped with NodeJS and Google Chrome, there was a bug that for scientific notation, the plurality of the units are determined by the mantissa:

Intl.NumberFormat('en', {style: 'unit', unit: 'gallon', unitDisplay: 'long', notation: 'scientific'}).format(10000)
//-> 1E4 gallon (singular form unit name because the mantissa is 1)

The earlier version of the polyfill acknowledges this quirk but decided to follow its behavior. Now it seems the latest version of NodeJS and Google Chrome both have this fixed now. The polyfill will also follow the new (and IMO correct) behavior:

Intl.NumberFormat('en', {style: 'unit', unit: 'gallon', unitDisplay: 'long', notation: 'scientific'}).format(10000)
//-> 1E4 gallons

@pyrocat101 pyrocat101 force-pushed the fixNumberFormatPlural branch from bf6f519 to 1a7df07 Compare September 7, 2020 11:21
@longlho
Copy link
Member

longlho commented Sep 7, 2020

Can you update should-polyfill as well to account for this bug?

@pyrocat101
Copy link
Member Author

@longlho Ok, with some digging, I think this is a bug in older versions of ICU (thus both Node 12.x and earlier versions of Chrome are affected): https://unicode-org.atlassian.net/browse/ICU-13836.

The fix is introduced earlier this year: unicode-org/icu#938

Do you think it is still worth detecting such bug in the polyfill?

@longlho
Copy link
Member

longlho commented Sep 7, 2020

Yeah i think we should allow polyfill to take over if we detect the bug

@pyrocat101
Copy link
Member Author

The latest minor version of Node 12.x also ships with ICU 67.1 and thus does not have the bug. I will include the detection anyway.

@pyrocat101 pyrocat101 force-pushed the fixNumberFormatPlural branch from 1a7df07 to 37e6718 Compare September 7, 2020 20:48
@pyrocat101 pyrocat101 merged commit 4f7f791 into main Sep 7, 2020
@pyrocat101 pyrocat101 deleted the fixNumberFormatPlural branch September 7, 2020 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants