-
Notifications
You must be signed in to change notification settings - Fork 2k
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
i18n: format-currency
- bring formatCurrency
method to i18n-calypso
#100097
base: trunk
Are you sure you want to change the base?
Conversation
Jetpack Cloud live (direct link)
Automattic for Agencies live (direct link)
|
Here is how your PR affects size of JS and CSS bundles shipped to the user's browser: App Entrypoints (~2011 bytes added 📈 [gzipped])
Common code that is always downloaded and parsed every time the app is loaded, no matter which route is used. Sections (~17 bytes added 📈 [gzipped])
Sections contain code specific for a given set of routes. Is downloaded and parsed only when a particular route is navigated to. Async-loaded Components (~17 bytes added 📈 [gzipped])
React components that are loaded lazily, when a certain part of UI is displayed for the first time. Legend What is parsed and gzip size?Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory. Generated by performance advisor bot at iscalypsofastyet.com. |
This PR modifies the release build for the following Calypso Apps: For info about this notification, see here: PCYsg-OT6-p2
To test WordPress.com changes, run |
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.
@sirbrillig / @Automattic/i18n this will be the new (temporary) home for all number-formatters, form this point on including currency. The handlers themselves are raw, without state. The i18n-calypso instance/prototype simply lends its internal state for locale/geoLocation.
Once we migrate everything into this location, we can deprecate entirely format-currency
and decide where to host number-formatters
(it might move to a JP package or elsewhere). We can then introduce state handling to it if we want (or just keep using the handlers thorugh the i18n-calypso & JP number-format packages (which are basically portals/proxies).
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.
Looks pretty good! I noticed one small edge case that I should have brought up in #99981
packages/i18n-calypso/src/number-formatters/number-format-currency/index.ts
Show resolved
Hide resolved
packages/i18n-calypso/src/number-formatters/number-format-currency/index.ts
Outdated
Show resolved
Hide resolved
packages/i18n-calypso/src/number-formatters/number-format-currency/index.ts
Show resolved
Hide resolved
if ( retries ) { | ||
return getCachedFormatter( { | ||
locale: fallbackLocale, | ||
options, | ||
retries: retries - 1, | ||
} ); | ||
} | ||
|
||
throw error; |
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.
Added a limit on retries so it doesn't end up in an infinite loop - theoretically, as that's unlikely to happen with a valid fallback locale. Also failing loudly if for whatever reason it happens.
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.
These tests are identical to format-currency package's, although they are done through the more primitive number-formatters interface (where we pass the locale and everything else as properties).
@@ -307,6 +307,73 @@ describe( 'I18n', function () { | |||
} ); | |||
} ); | |||
|
|||
describe( 'formatCurrency', () => { |
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 tests here combined with the primitive ones above should result in the same coverage as originally in format-currency package's. We basically test that the state handled properties (locale
& geoLocation
) propagate propagate properly into number-formatters.
This is now ready for testing. The plan billing descriptions are set through this method now. See testing instructions. Once we deploy here, the next couple of PRs will aim at bringing cc @sirbrillig / @Automattic/i18n |
…llest-unit numbers
33a6230
to
7eb8d35
Compare
ah sorry for the wide ping. rebased then changed parent here |
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 works as described for me. The only thing I wasn't sure how to test is the logged-out plans page, and I'm not sure if that even uses these same code paths.
Thanks @sirbrillig ! Did you mean the p.s. since you mentioned I checked, and it looks like the currencies aren't localised properly or consistently there. I'll send these out in a P2 post so it gets looked at:
![]()
![]()
![]() |
Well actually, let me tag someone from @Automattic/martech-autobots. For context - in EL/DE, symbol follows the number e.g. |
Part of addressing https://github.com/Automattic/i18n-issues/issues/939
Based off #100008
Proposed Changes
We bring the
formatCurrency
method to i18n-calypso to begin centralizing with the other number-formatters.format-currency
package - there is stillgetCurrencyObject
to migrate.formatCurrency
function either. We will target one consumer scenario, the plan prices, to verify. We will do the rest in follow-ups.This is a crucial refactor and creates the point from which we absolutely need to push through the remaining work (to bring currency formatting in full into i18n-calypso and deprecate format-currency). In this state, there is insane duplication and risk.
Why are these changes being made?
This is part of addressing https://github.com/Automattic/i18n-issues/issues/939, which aims at unifying number & currency-number formatting
TODO
format-currency
package.Testing Instructions
/start/plans
and/plans/:site
For EL locale & USD:
Pre-merge Checklist