MCPcopy Create free account
hub / github.com/violentmonkey/violentmonkey / getLocaleString

Function getLocaleString

src/common/string.js:30–42  ·  view source on GitHub ↗
(meta, key, languages = navigator.languages)

Source from the content-addressed store, hash-verified

28 * Get locale attributes such as `@name:zh-CN`
29 */
30export 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
44export function getFullUrl(url, base) {
45 let obj;

Callers 3

index.test.jsFile · 0.90
initScriptFunction · 0.90
getScriptNameFunction · 0.90

Calls 4

localeMatchFunction · 0.85
mapMethod · 0.80
filterMethod · 0.80
findMethod · 0.80

Tested by

no test coverage detected