Skip to content

Commit

Permalink
feat(i18n): ca-valencia language detection in Edge browser (#1828)
Browse files Browse the repository at this point in the history
  • Loading branch information
userquin committed Feb 28, 2023
1 parent 2ccec5e commit baba3fa
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions utils/language.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit baba3fa

Please sign in to comment.