Skip to content

i18n: Update formatCurrency / getCurrencyObject imports to be from @automattic/number-formatters#42796

Merged
chriskmnds merged 19 commits intotrunkfrom
update/i18n-number-formatters-formatCurrency
May 6, 2025
Merged

i18n: Update formatCurrency / getCurrencyObject imports to be from @automattic/number-formatters#42796
chriskmnds merged 19 commits intotrunkfrom
update/i18n-number-formatters-formatCurrency

Conversation

@chriskmnds
Copy link
Copy Markdown
Contributor

@chriskmnds chriskmnds commented Mar 31, 2025

See PT: pxLjZ-9ME-p2
Part of addressing https://github.com/Automattic/i18n-issues/issues/942

Proposed changes:

This PR follows from the work in #42746 to implement the new @automattic/number-formatters package.

  • Update formatCurrnecy & getCurrencyObject imports from @automattic/format-currency to go through the new @automattic/number-formatters package

This does not deprecate @automattic/format-currency yet. There are remaining usages with obsolete methods, something that will be handled elsewhere e.g. in #42456 and #42457

Media

Pricing cards e.g. at /wp-admin/admin.php?page=my-jetpack#/add-backup

EN (. decimal separator) EL/DE (, decimal separator)
Screenshot 2025-05-05 at 12 49 07 PM Screenshot 2025-05-05 at 1 08 46 PM

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

Does this pull request change what data or activity we track or use?

Testing instructions:

  1. Build passing
  2. Instructions for manual testing a few cases (locally, for posterity/ future reference):

Follow the instructions to run JP in Docker and build the Jetpack plugin. Once the env is ready, the rest boils down to:

  • cp tools/docker/default.env tools/docker/.env
  • jp docker up -d
  • for some reason, we need this back: cp tools/docker/default.env tools/docker/.env
  • jp docker install - may need to wait a bit first
  • jp build plugins/jetpack --deps - this will take a while
  • jp watch - obviously for testing/debugging things
  • To show the pricing cards/plans and activate various JP plugins, you'll need to tunnel a normal domain to localhost. So Jurassic Tube to the rescue. Follow instructions: PCYsg-GJ2-p2

Example – The pricing/plan cards for getting a plan for certain plugins under my-jetpack:

  • Go to /wp-admin/admin.php?page=my-jetpack, then click on "Get Plan" under "VaultPress Backup"
  • The above should take you to /wp-admin/admin.php?page=my-jetpack#/add-backup
  • Go to /wp-admin/profile.php and switch locale/language between Greek/Deutsch, and English.
  • Confirm the prices render with correct formatting. Per the media above.

@chriskmnds chriskmnds self-assigned this Mar 31, 2025
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 31, 2025

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack or WordPress.com Site Helper), and enable the update/i18n-number-formatters-formatCurrency branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack update/i18n-number-formatters-formatCurrency
bin/jetpack-downloader test jetpack-mu-wpcom-plugin update/i18n-number-formatters-formatCurrency

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions github-actions bot added [Block] Donations [JS Package] Components [JS Package] Number Formatters [Package] Backup [Package] My Jetpack [Package] Search Contains core Search functionality for Jetpack and Search plugins [Plugin] Boost A feature to speed up the site and improve performance. [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Status] In Progress [Tests] Includes Tests Admin Page React-powered dashboard under the Jetpack menu RNA labels Mar 31, 2025
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 31, 2025

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add a "[Type]" label (Bug, Enhancement, Janitorial, Task).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!


Jetpack plugin:

No scheduled milestone found for this plugin.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Boost plugin:

No scheduled milestone found for this plugin.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

@github-actions github-actions bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Mar 31, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the currency formatting imports across the codebase to use the new package (@automattic/number-formatters) instead of the legacy @automattic/format-currency. These changes ensure that both formatCurrency and getCurrencyObject are consistently imported from the new package, aligning with the updated initialization requirements.

Reviewed Changes

Copilot reviewed 19 out of 27 changed files in this pull request and generated no comments.

Show a summary per file
File Description
projects/plugins/jetpack/extensions/blocks/donations/deprecated/v1/index.js Replaced default and named imports from the old package with separate imports for CURRENCIES and formatCurrency.
projects/plugins/jetpack/extensions/blocks/donations/amount.js Updated the imports for formatCurrency and CURRENCIES to their new sources.
projects/plugins/jetpack/_inc/client/recommendations/product-card-upsell/index.jsx Swapped getCurrencyObject import to use the new package.
projects/plugins/jetpack/_inc/client/recommendations/feature-utils.js Removed old formatCurrency import and added the new import from @automattic/number-formatters.
projects/plugins/jetpack/_inc/client/components/jetpack-product-card/test/component.js Updated getCurrencyObject import for consistency in test files.
projects/plugins/boost/app/assets/src/js/features/upgrade-cta/upgrade-cta.tsx Replaced getCurrencyObject import with the new package import.
projects/packages/search/src/dashboard/components/price/index.jsx Updated getCurrencyObject import accordingly.
projects/packages/my-jetpack/_inc/components/product-detail-card/index.jsx Adjusted getCurrencyObject import to align with new formatting conventions.
projects/packages/my-jetpack/_inc/components/product-card/pricing-component.tsx Replaced formatCurrency import with the new package version.
projects/packages/backup/src/js/components/backup-storage-space/storage-addon-upsell-prompt/price.js Updated the getCurrencyObject import to use the new package.
projects/js-packages/components/components/product-price/price.tsx Changed getCurrencyObject import to the new package import.
projects/js-packages/components/components/pricing-card/index.tsx Updated getCurrencyObject import to maintain consistency across components.
Files not reviewed (8)
  • projects/js-packages/components/changelog/update-i18n-number-formatters-formatCurrency: Language not supported
  • projects/js-packages/number-formatters/changelog/update-i18n-number-formatters-formatCurrency: Language not supported
  • projects/packages/backup/changelog/update-i18n-number-formatters-formatCurrency: Language not supported
  • projects/packages/my-jetpack/changelog/update-i18n-number-formatters-formatCurrency: Language not supported
  • projects/packages/my-jetpack/package.json: Language not supported
  • projects/packages/search/changelog/update-i18n-number-formatters-formatCurrency: Language not supported
  • projects/plugins/boost/changelog/update-i18n-number-formatters-formatCurrency: Language not supported
  • projects/plugins/jetpack/changelog/update-i18n-number-formatters-formatCurrency: Language not supported

@chriskmnds chriskmnds added the Enhancement Changes to an existing feature — removing, adding, or changing parts of it label Mar 31, 2025
@jp-launch-control
Copy link
Copy Markdown

jp-launch-control bot commented Mar 31, 2025

Code Coverage Summary

This PR did not change code coverage!

That could be good or bad, depending on the situation. Everything covered before, and still is? Great! Nothing was covered before? Not so great. 🤷

Full summary · PHP report · JS report

@chriskmnds chriskmnds force-pushed the update/i18n-number-formatters-v1 branch from c5c11ce to fcee859 Compare April 1, 2025 14:32
@chriskmnds chriskmnds force-pushed the update/i18n-number-formatters-formatCurrency branch from 8a118ce to 68b9fe3 Compare April 1, 2025 14:38
@chriskmnds chriskmnds requested a review from Copilot April 1, 2025 16:12
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the currency formatting imports to use the new @automattic/number-formatters package and adjusts the underlying initialization and fallback logic for locale settings.

  • Updated import statements for formatCurrency and getCurrencyObject across several files.
  • Modified create-number-formatters.ts to use state variables (localeState and geoLocationState) and a fallback chain via getBrowserSafeLocale.
  • Ensured consistency in how locale information is derived using the new package's API.

Reviewed Changes

Copilot reviewed 18 out of 27 changed files in this pull request and generated no comments.

Show a summary per file
File Description
projects/plugins/jetpack/_inc/client/recommendations/product-card-upsell/index.jsx Updated getCurrencyObject import
projects/plugins/jetpack/_inc/client/recommendations/feature-utils.js Updated formatCurrency import
projects/plugins/jetpack/_inc/client/components/jetpack-product-card/test/component.js Updated getCurrencyObject import in tests
projects/plugins/boost/app/assets/src/js/features/upgrade-cta/upgrade-cta.tsx Updated getCurrencyObject import
projects/packages/search/src/dashboard/components/price/index.jsx Updated getCurrencyObject import
projects/packages/my-jetpack/_inc/components/product-detail-card/index.jsx Updated getCurrencyObject import
projects/packages/my-jetpack/_inc/components/product-card/pricing-component.tsx Updated formatCurrency import
projects/packages/backup/src/js/components/backup-storage-space/storage-addon-upsell-prompt/price.js Updated getCurrencyObject import
projects/js-packages/number-formatters/src/create-number-formatters.ts Updated locale and geoLocation logic
projects/js-packages/components/components/product-price/price.tsx Updated getCurrencyObject import
projects/js-packages/components/components/pricing-card/index.tsx Updated getCurrencyObject import
Files not reviewed (9)
  • pnpm-lock.yaml: Language not supported
  • projects/js-packages/components/changelog/update-i18n-number-formatters-formatCurrency: Language not supported
  • projects/js-packages/number-formatters/changelog/update-i18n-number-formatters-formatCurrency: Language not supported
  • projects/js-packages/number-formatters/package.json: Language not supported
  • projects/packages/backup/changelog/update-i18n-number-formatters-formatCurrency: Language not supported
  • projects/packages/my-jetpack/changelog/update-i18n-number-formatters-formatCurrency: Language not supported
  • projects/packages/my-jetpack/package.json: Language not supported
  • projects/packages/search/changelog/update-i18n-number-formatters-formatCurrency: Language not supported
  • projects/plugins/boost/changelog/update-i18n-number-formatters-formatCurrency: Language not supported
Comments suppressed due to low confidence (1)

projects/js-packages/number-formatters/src/create-number-formatters.ts:150

  • [nitpick] Consider renaming 'localeState' to 'browserSafeLocale' (or a similar name) to more clearly reflect its purpose in normalizing and providing the locale for formatting.
localeState = locale;

Base automatically changed from update/i18n-number-formatters-v1 to trunk April 2, 2025 09:09
@github-actions github-actions bot added the Docs label Apr 2, 2025
@chriskmnds chriskmnds force-pushed the update/i18n-number-formatters-formatCurrency branch from 6e41270 to 4b979f7 Compare May 5, 2025 15:50
@chriskmnds chriskmnds requested a review from a team May 5, 2025 16:16
@chriskmnds
Copy link
Copy Markdown
Contributor Author

All the checks pass, and I tested a couple of cases (in description). There are obviously more usages, but I don't have a fully activated local environment yet e.g., an upsell with price rendering in the Backup plugin I can't get to yet. I'll be doing more testing for the other PRs too.

Ok to go with this? @anomiex / @Automattic/martech

anomiex
anomiex previously approved these changes May 5, 2025
Copy link
Copy Markdown
Contributor

@anomiex anomiex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable to me (flagged one nitpick though). But I didn't try to test any of the functionality.

"webpack-cli": "6.0.1"
}
}
} No newline at end of file
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove the newline from the end of the file?

Same in other files below.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure. It's not flagged as a violation for package.json files, apparently. I have my editor set up to apply linting when saving, so these get removed (I think the root issue is elsewhere though). Something to do with the lining configuration perhaps, cause it's not the case in Calypso (for example - .json files are parsed with eol-last like regular JS).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. But curious why this isn't part of linting. It should have been flagged

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have any eslint set up for package.json files. Yet, anyway.

Probably your editor or something saves them without the trailing newline, then in Calypso linting fixes it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Admin Page React-powered dashboard under the Jetpack menu [Block] Donations Docs Enhancement Changes to an existing feature — removing, adding, or changing parts of it [JS Package] Components [JS Package] Number Formatters [Package] Backup [Package] My Jetpack [Package] Search Contains core Search functionality for Jetpack and Search plugins [Package] Subscribers Dashboard [Plugin] Boost A feature to speed up the site and improve performance. [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ RNA [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants