From 6647e08dbcfda0747f9c0de1cc39f53b220a79b7 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 0b9f1d90..7a93c883 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