From b1aa4aad6062ebfe4642a5cd3d0902858f9a25f0 Mon Sep 17 00:00:00 2001 From: Thomas Zemp Date: Fri, 5 Jul 2024 10:02:04 +0200 Subject: [PATCH] fix: pass valid locale for number formatting [DHIS2-17709] --- 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