From c671734edb49231b4dd2cabdd03b0699b45bf273 Mon Sep 17 00:00:00 2001 From: Christos Date: Fri, 17 Jan 2025 11:54:27 +0200 Subject: [PATCH] force latin number encoding by default --- client/lib/format-number-compact/test/index.js | 4 ++-- packages/i18n-calypso/src/i18n.js | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/client/lib/format-number-compact/test/index.js b/client/lib/format-number-compact/test/index.js index 161c0dada48b2..772de50eac87d 100644 --- a/client/lib/format-number-compact/test/index.js +++ b/client/lib/format-number-compact/test/index.js @@ -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', () => { diff --git a/packages/i18n-calypso/src/i18n.js b/packages/i18n-calypso/src/i18n.js index d9bcc900c37ac..edc0e17381c5e 100644 --- a/packages/i18n-calypso/src/i18n.js +++ b/packages/i18n-calypso/src/i18n.js @@ -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)