From c1254702ad7d33024fed680a08399a47e38d07c7 Mon Sep 17 00:00:00 2001 From: royallsilwallz Date: Fri, 10 May 2024 18:03:19 +0545 Subject: [PATCH 1/3] Fix mismatch value for language json file for Nederlands - Related to #6425 --- frontend/src/utils/internationalization.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/utils/internationalization.js b/frontend/src/utils/internationalization.js index aa5bf50cd1..c9cbc2b3f3 100644 --- a/frontend/src/utils/internationalization.js +++ b/frontend/src/utils/internationalization.js @@ -24,7 +24,7 @@ const supportedLocales = [ { value: 'ko', label: '한국어' }, // { value: 'mg', label: 'Malagasy' }, // { value: 'ml', label: 'Malayalam' }, - { value: 'nl', label: 'Nederlands' }, + { value: 'nl_NL', label: 'Nederlands' }, { value: 'pt', label: 'Português' }, { value: 'pt-BR', label: 'Português (Brasil)' }, // { value: 'ru', label: 'Русский язык' }, From 6e53dc6652627fa30922b584775f6348e19c758b Mon Sep 17 00:00:00 2001 From: royallsilwallz Date: Fri, 10 May 2024 18:04:44 +0545 Subject: [PATCH 2/3] Fix test case failure for `nl_NL` language - Related to #6425 --- frontend/src/utils/countries.js | 3 ++- frontend/src/utils/tests/internationalization.test.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/frontend/src/utils/countries.js b/frontend/src/utils/countries.js index e474c35010..d014cf0a8a 100644 --- a/frontend/src/utils/countries.js +++ b/frontend/src/utils/countries.js @@ -20,7 +20,8 @@ export function getCountryCode(name) { } export function isLangSupported(code) { - if (getSupportedLangs().includes(code.split('-')[0])) return true; + // split with `-` or `_` to get the language initials + if (getSupportedLangs().includes(code.split(/[-_]/)[0])) return true; return false; } diff --git a/frontend/src/utils/tests/internationalization.test.js b/frontend/src/utils/tests/internationalization.test.js index 65f29cea46..17e41ff5c4 100644 --- a/frontend/src/utils/tests/internationalization.test.js +++ b/frontend/src/utils/tests/internationalization.test.js @@ -31,7 +31,7 @@ describe('getSupportedLocale', () => { it('returns a generic supported locale if the variation is not supported', () => { expect(getSupportedLocale('en-gb')).toEqual({ label: 'English', value: 'en' }); expect(getSupportedLocale('es-AR')).toEqual({ label: 'Español', value: 'es' }); - expect(getSupportedLocale('nl-NL')).toEqual({ label: 'Nederlands', value: 'nl' }); + expect(getSupportedLocale('nl_NL')).toEqual({ label: 'Nederlands', value: 'nl_NL' }); }); it('returns the default locale if the code is not supported and does not have a variation', () => { expect(getSupportedLocale('xt')).toEqual({ label: 'English', value: 'en' }); From 0f4a5456169aef6cb9d3a70e23eea19b6000b2b7 Mon Sep 17 00:00:00 2001 From: royallsilwallz Date: Mon, 13 May 2024 14:09:49 +0545 Subject: [PATCH 3/3] Fix undefined issue when language toggle to Nederlands - Related to #6425 --- frontend/src/utils/countries.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/utils/countries.js b/frontend/src/utils/countries.js index d014cf0a8a..1d9382d7d4 100644 --- a/frontend/src/utils/countries.js +++ b/frontend/src/utils/countries.js @@ -2,7 +2,7 @@ import { getCountries, getCountry, getSupportedLangs } from '@hotosm/iso-countri export function translateCountry(name, locale) { const code = getCountryCode(name); - if (code && isLangSupported(locale)) return getCountry(locale.split('-')[0], code); + if (code && isLangSupported(locale)) return getCountry(locale.split(/[-_]/)[0], code); return name; } @@ -27,7 +27,7 @@ export function isLangSupported(code) { export function formatCountryList(locale) { if (locale && isLangSupported(locale)) { - const countries = getCountries(locale.split('-')[0]); + const countries = getCountries(locale.split(/[-_]/)[0]); return Object.keys(countries).map((key) => ({ label: countries[key], value: key })); } }