Skip to content

Commit

Permalink
force latin number encoding by default
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskmnds committed Jan 17, 2025
1 parent ba48722 commit 6957664
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions client/lib/format-number-compact/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,11 @@ describe( 'formatNumberCompact', () => {
} );
test( 'shows 2 sig figs for counts < 10000', () => {
const counts = formatNumberCompact( 1234, 'ar' );
expect( counts ).toEqual( '١٫٢ ألف' );
expect( counts ).toEqual( '1.2 ألف' );
} );
test( 'shows leading sig figs for counts > 10000', () => {
const counts = formatNumberCompact( 123456, 'ar' );
expect( counts ).toEqual( '١٢٣ ألف' );
expect( counts ).toEqual( '123 ألف' );
} );
} );
describe( 'sv', () => {
Expand Down
5 changes: 3 additions & 2 deletions packages/i18n-calypso/src/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,15 @@ I18N.prototype.emit = function ( ...args ) {
* Formats numbers using locale settings and/or passed options.
* @param {string | number} number to format (required)
* @param {number | Object} options Number of decimal places or options object (optional)
* @param {boolean} forceLatin Whether to use latin numbers by default (optional. default = true)
* @returns {string | number} Formatted number as string, or original number if formatting fails
*/
I18N.prototype.numberFormat = function ( number, options = {} ) {
I18N.prototype.numberFormat = function ( number, options = {}, forceLatin = true ) {
const decimals = typeof options === 'number' ? options : options.decimals || 0;
const browserSafeLocale = this.getBrowserSafeLocale();

try {
return Intl.NumberFormat( browserSafeLocale, {
return Intl.NumberFormat( `${ browserSafeLocale }${ forceLatin ? '-u-nu-latn' : '' }`, {
minimumFractionDigits: decimals, // default is 0
maximumFractionDigits: decimals, // default is the greater between minimumFractionDigits and 3
// TODO clk numberFormat this may be the only difference, where some cases use 2 (they can just pass the option to Intl.NumberFormat)
Expand Down

0 comments on commit 6957664

Please sign in to comment.