From baba3faa34a4189236fdb72573d89f2a1e323f9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20S=C3=A1nchez?= Date: Tue, 28 Feb 2023 22:36:05 +0100 Subject: [PATCH] feat(i18n): `ca-valencia` language detection in Edge browser (#1828) --- utils/language.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/utils/language.ts b/utils/language.ts index 3e26aee9..76438af0 100644 --- a/utils/language.ts +++ b/utils/language.ts @@ -2,12 +2,19 @@ export function matchLanguages(languages: string[], acceptLanguages: readonly st { // const lang = acceptLanguages.map(userLang => languages.find(lang => lang.startsWith(userLang))).filter(v => !!v)[0] // TODO: Support es-419, remove this code if we include spanish country variants - const lang = acceptLanguages.map(userLang => languages.find((lang) => { - if (userLang.startsWith('es-') && userLang !== 'es-ES') - return lang === 'es-419' + const lang = acceptLanguages.map(userLang => languages.find((currentLang) => { + if (currentLang === userLang) + return currentLang - return lang.startsWith(userLang) - })).filter(v => !!v)[0] + // Edge browser: case for ca-valencia + if (currentLang === 'ca-valencia' && userLang === 'ca-Es-VALENCIA') + return currentLang + + if (userLang.startsWith('es-') && userLang !== 'es-ES' && currentLang === 'es-419') + return currentLang + + return currentLang.startsWith(userLang) ? currentLang : undefined + })).filter(v => !!v)?.[0] if (lang) return lang }