Automattic / wp-calypso

The JavaScript and API powered WordPress.com
https://developer.wordpress.com
GNU General Public License v2.0
12.42k stars 1.99k forks source link

I18n: Use Intl.NumberFormat, deprecate i18n-calypso's numberFormat #46564

Open ockham opened 4 years ago

ockham commented 4 years ago

First brought up by @tyxla here: https://github.com/Automattic/wp-calypso/pull/28846#pullrequestreview-178381258

As we're moving to use @wordpress/i18n over calypso-i18n, numberFormat is one of the tools that is holding us back, as it's still used by a lot of code. See e.g. this JP PR by @jeherve that removes the explicit i18n-calypso dependency, but still retains it in its lockfile, as it's required transitively by @automattic/format-currency.

It'd be great if we could replace usage of i18n-calypso's numberFormat by Intl.NumberFormat, which seems to be widely supported.

Note that the API (function signature) is quite different: e.g. Intl.NumberFormat requires an explicit locale arg.

cc/ @Automattic/team-calypso

jeherve commented 4 years ago

It'd be great if we could replace usage of i18n-calypso's numberFormat by Intl.NumberFormat

That's also the approach we took in Jetpack:

An alternative may be to bring this functionality to Core itself, as discussed here: https://github.com/WordPress/gutenberg/issues/22628

While Core may not have much use for a function used to localize the display of currency amounts (this seems to be plugin territory), I think it'd be useful to have a general number formatting function there.

github-actions[bot] commented 3 years ago

This issue is stale because it has been 180 days with no activity. You can keep the issue open by adding a comment. If you do, please provide additional context and explain why you’d like it to remain open. You can also close the issue yourself — if you do, please add a brief explanation and apply one of relevant issue close labels.

tyxla commented 3 years ago

cc @Automattic/i18n and @yuliyan in case this is something interesting to consider.