From 460a87acef1ccc11dc0716bbbcfc9669f36a10ed Mon Sep 17 00:00:00 2001 From: Thomas Zemp Date: Mon, 15 Jul 2024 08:56:19 +0200 Subject: [PATCH] fix: pass valid locale for number formatting [DHIS2-17709] (#1352) --- src/settingsKeyMapping.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/settingsKeyMapping.js b/src/settingsKeyMapping.js index e145f819..3fa4d72a 100644 --- a/src/settingsKeyMapping.js +++ b/src/settingsKeyMapping.js @@ -4,8 +4,15 @@ const canBeOverridenLabel = i18n.t( 'This setting can be overridden by user settings' ) +const parseLocale = (localeString) => { + const [language, country] = (localeString ?? 'en').split(/[-_]/) + return `${language}${country ? `-${country}` : ''}` +} + +const parsedLocale = parseLocale(i18n.language) + const formatNumber = (value) => - new Intl.NumberFormat(i18n.language).format(value) + new Intl.NumberFormat(parsedLocale).format(value) /** * This file provides information about DHIS2 system settings and configuration options that are not otherwise