mirror of
https://github.com/elk-zone/elk
synced 2024-11-23 22:56:09 +09:00
17 lines
487 B
TypeScript
17 lines
487 B
TypeScript
export function matchLanguages(languages: string[], acceptLanguages: readonly 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
|
|
}
|