1
0
elk/utils/language.ts
2023-01-13 01:52:52 +08:00

17 lines
478 B
TypeScript

export function matchLanguages(languages: string[], acceptLanguages: string[]): string | null {
{
const lang = acceptLanguages.map(userLang => languages.find(lang => lang.startsWith(userLang))).filter(v => !!v)[0]
if (lang)
return lang
}
const lang = acceptLanguages.map((userLang) => {
userLang = userLang.split('-')[0]!
return languages.find(lang => lang.startsWith(userLang))
}).filter(v => !!v)[0]
if (lang)
return lang
return null
}