diff --git a/frontend/src/utils/countries.js b/frontend/src/utils/countries.js index e474c35010..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; } @@ -20,13 +20,14 @@ 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; } 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 })); } } 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: 'Русский язык' }, 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' });