Skip to content

number-formatters: Resolve the WordPress locale to its nearest supported tag - #55479

Merged
dognose24 merged 6 commits into
trunkfrom
fix/number-formatters-wp-locale-tag
Nov 27, 2026
Merged

dognose24 merged 6 commits into
trunkfrom
fix/number-formatters-wp-locale-tag

Conversation

@dognose24

@dognose24 dognose24 commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Proposed changes

  • getBrowserSafeLocale() kept only the language of a WordPress locale name (zh_TW → zh), so every number went through Simplified Chinese on a Traditional Chinese site, and regional conventions were lost everywhere else. It now turns the name into a BCP 47 tag and drops subtags from the right until Intl.NumberFormat supports the rest: zh_TW → zh-TW, pt_PT_ao90 → pt-PT, de_DE_formal → de-DE-formal. A name nothing in Intl supports (ary) falls through to the next source, the browser's language, and then to en, as before.
  • setLocale() values go through the same resolution, so setLocale( 'zh_TW' ) works too.
  • A name resolves once: every number formats through this path, and a WordPress variant such as pt_PT_ao90 threw once per call before settling, so the result is kept by name.

What a visitor sees, formatting 1,620,000 in compact notation and 1,234,567 in full:

WordPress locale Before After
zh_TW 162万 162萬
zh_HK 162万 1.6M
en_GB 1.6M 1.6m
es_MX 1.234.567 1,234,567
pt_PT_ao90 1.234.567 (as pt, Brazilian) 1 234 567

The dashboard's dates already resolve the locale this way in @jetpack-premium-analytics/formatters, which is how the mismatch showed: Stats v2 on a zh_TW site wrote dates in Traditional Chinese and every figure in Simplified.

Changelog entries go to the plugins whose own screens format figures with the package: plugins/jetpack (Stats, My Jetpack, Forms, Newsletter, Monetize), plugins/stats, plugins/premium-analytics, plugins/backup (storage sizes and prices), plugins/boost (performance history), plugins/search (record counts and prices) and plugins/social (upgrade prices). The remaining bundling plugins reach it only through My Jetpack cards.

Related product discussion/links

  • Found while testing the Jetpack Stats AI tab on a zh_TW site.

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

No.

Testing instructions

  • jp test js js-packages/number-formatters: the locale suite has the new cases.
  • On a site whose language is Traditional Chinese (繁體中文), open Jetpack Stats. Compact figures read 162萬, not 162万.
  • With the site in English (UK), compact figures read 1.6m, as the browser would format them for en-GB.

What I ran:

  • The package's Jest suite (5 suites, 114 tests), tsc --noEmit and ESLint on the changed files.
  • The zh_TW case in Chrome on a local Jetpack site with Stats v2.

🤖 Generated with Claude Code

…ted tag

The fallback locale kept only the language of a WordPress locale name, so
`zh_TW` formatted as `zh`, Simplified Chinese, and regional conventions
were lost everywhere. Subtags now drop from the right until Intl supports
the rest, so `zh_TW` becomes `zh-TW` and `pt_PT_ao90` becomes `pt-PT`.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@dognose24 dognose24 added Bug When a feature is broken and / or not performing as intended [Status] Needs Review This PR is ready for review. labels Nov 26, 2026
@dognose24 dognose24 self-assigned this Nov 26, 2026
@dognose24
dognose24 requested a review from chriskmnds November 26, 2026 03:10
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

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 fix/number-formatters-wp-locale-tag branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack fix/number-formatters-wp-locale-tag
bin/jetpack-downloader test jetpack-mu-wpcom-plugin fix/number-formatters-wp-locale-tag

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 commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

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 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:

The Jetpack plugin has different release cadences depending on the platform:

  • WordPress.com Simple releases happen as soon as you deploy your changes after merging this PR (PCYsg-Jjm-p2).
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly:
    • Scheduled release: December 8, 2026
    • Code freeze: December 7, 2026

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


Backup 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.


Search 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.


Social 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.


Protect 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.


Videopress 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.


Premium Analytics 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.


Stats Data 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.

@dognose24
dognose24 requested review from a team and alshakero and a balanced review from Copilot November 26, 2026 03:12
…s whose screens change

Every number formats through the resolution, and a WordPress variant such
as `pt_PT_ao90` threw once per call before settling, so the result is kept
by name. Backup, Boost, Search and Social format figures of their own with
the package, so they get the changelog entry too.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@dognose24
dognose24 requested a review from a team as a code owner November 26, 2026 03:17
A lookup that fails while Intl is unavailable, as a test stubs it, must not
stick to the name; a miss is cheap to repeat.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@github-actions github-actions Bot added [Plugin] Backup A plugin that allows users to save every change and get back online quickly with one-click restores. [Plugin] Boost A feature to speed up the site and improve performance. [Plugin] Search A plugin to add an instant search modal to your site to help visitors find content faster. [Plugin] Social Issues about the Jetpack Social plugin labels Nov 26, 2026
@jp-launch-control

jp-launch-control Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/js-packages/number-formatters/src/create-number-formatters.ts 42/43 (97.67%) 1.67% 0 💚

Full summary · PHP report · JS report

Copilot AI left a comment

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.

🟡 Changes recommended

Locale resolution repeats avoidable validation work on every formatted value, and forceLatin creates invalid tags for locales with existing Unicode extensions, causing POSIX formatting to fall back to English.

2 open issues
What changed in this PR

This PR updates the shared number-formatters package to preserve WordPress locale regions and variants where supported, improving Traditional Chinese and regional number formatting.

Changes:

  • Resolve locale names to supported tags, falling back through configured, WordPress, browser, and default locales.
  • Add tests for regional formatting, WordPress variants, setLocale(), and unsupported locales.
  • Add package and Stats-related plugin changelog entries.
File Description
projects/​plugins/​stats/​changelog/​fix-number-formatters-wp-locale-tag Document the Stats formatting fix.
projects/​plugins/​premium-analytics/​changelog/​fix-number-formatters-wp-locale-tag Document the Premium Analytics formatting fix.
projects/​plugins/​jetpack/​changelog/​fix-number-formatters-wp-locale-tag Document improvements for Stats and My Jetpack.
projects/​js-packages/​number-formatters/​src/​test/​create-number-formatters-locale.test.ts Cover locale resolution and fallback behavior.
projects/​js-packages/​number-formatters/​src/​create-number-formatters.ts Normalize locale tags and resolve supported candidates.
projects/​js-packages/​number-formatters/​changelog/​fix-number-formatters-wp-locale-tag Record the shared package’s formatting improvements.

Review effort: Balanced

…al form

Canonicalizing turns `en-US-posix` into `en-US-u-va-posix`, which the
`-u-nu-latn` suffix for `forceLatin` cannot follow, so such a locale fell
back to English. `supportedLocalesOf()` validates the tag on its own.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
chihsuan
chihsuan previously approved these changes Nov 26, 2026

@chihsuan chihsuan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice catch on the 万/萬 mismatch! @dognose24 LGTM. Before this merges, could we add changelog entries for plugins/protect and plugins/videopress? Protect's firewall stat cards and the VideoPress dashboard's views chart both format with this package on their own screens.

Protect's firewall stat cards format with StatCard and the VideoPress
views chart with @automattic/charts, both of which use this package.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@dognose24

Copy link
Copy Markdown
Contributor Author

Added the two entries in 5aad2de. Both reach the package the way you said: Protect through StatCard and VideoPress through the @automattic/charts axis ticks.

@github-actions github-actions Bot added [Plugin] Protect A plugin with features to protect a site: brute force protection, security scanning, and a WAF. [Plugin] VideoPress A standalone plugin to add high-quality VideoPress videos to your site. labels Nov 26, 2026
@dognose24
dognose24 requested a review from chihsuan November 27, 2026 01:41
chihsuan
chihsuan previously approved these changes Nov 27, 2026

@chihsuan chihsuan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the updates! @dognose24 LGTM 🚀

1234567,
'1\u00a0234\u00a0567',
],
[ 'de_DE_formal', 'keeps a variant Intl accepts', 1234567, '1.234.567' ],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: Would it be worth dropping the de_DE_formal row? de and de-DE-formal both format as 1.234.567, so it still passes with the old .split( '_' )[ 0 ].

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.

Good catch, that row proved nothing. Swapped it for de_CH_informal in 503cedd6a rather than dropping it, so a WordPress name with a variant Intl accepts is still covered. Plain de gives 1.234.567 and de-CH-informal gives 1'234'567, and the row fails on the old lookup.

de_DE_formal formats like plain de, so its row passed on the old language-only
lookup too. de_CH_informal groups with an apostrophe, which only the region gives.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@dognose24
dognose24 requested a review from chihsuan November 27, 2026 04:23
@dognose24
dognose24 merged commit 8f4b973 into trunk Nov 27, 2026
190 of 191 checks passed
@dognose24
dognose24 deleted the fix/number-formatters-wp-locale-tag branch November 27, 2026 06:52
@github-actions github-actions Bot removed the [Status] Needs Review This PR is ready for review. label Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug When a feature is broken and / or not performing as intended [JS Package] Number Formatters [Plugin] Backup A plugin that allows users to save every change and get back online quickly with one-click restores. [Plugin] Boost A feature to speed up the site and improve performance. [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Plugin] Premium Analytics [Plugin] Protect A plugin with features to protect a site: brute force protection, security scanning, and a WAF. [Plugin] Search A plugin to add an instant search modal to your site to help visitors find content faster. [Plugin] Social Issues about the Jetpack Social plugin [Plugin] Stats Data [Plugin] VideoPress A standalone plugin to add high-quality VideoPress videos to your site. RNA [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants