(meta, key, languages = navigator.languages)
| 28 | * Get locale attributes such as `@name:zh-CN` |
| 29 | */ |
| 30 | export function getLocaleString(meta, key, languages = navigator.languages) { |
| 31 | // zh, zh-cn, zh-tw |
| 32 | const mls = Object.keys(meta) |
| 33 | .filter(metaKey => metaKey.startsWith(key + ':')) |
| 34 | .map(metaKey => metaKey.slice(key.length + 1)) |
| 35 | .sort((a, b) => b.length - a.length); |
| 36 | let bestLocale; |
| 37 | for (const lang of languages) { |
| 38 | bestLocale = mls.find(ml => localeMatch(lang, ml)); |
| 39 | if (bestLocale) break; |
| 40 | } |
| 41 | return meta[bestLocale ? `${key}:${bestLocale}` : key] || ''; |
| 42 | } |
| 43 | |
| 44 | export function getFullUrl(url, base) { |
| 45 | let obj; |
no test coverage detected