MCPcopy Create free account
hub / github.com/scriptscat/scriptcat / getLanguage

Method getLanguage

src/pkg/config/config.ts:395–416  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

393 }
394
395 async getLanguage() {
396 if (globalThis.localStorage) {
397 const cachedLanguage = localStorage.getItem("language");
398 if (cachedLanguage) {
399 return cachedLanguage;
400 }
401 }
402 return this._get<string>("language", {
403 // 取预设值时呼叫 asyncValue 进行异步取值
404 asyncValue() {
405 return matchLanguage().then((matchLanguageRes) => {
406 return matchLanguageRes || chrome.i18n.getUILanguage();
407 });
408 },
409 }).then((lng) => {
410 // 设置进入缓存
411 if (globalThis.localStorage) {
412 localStorage.setItem("language", `${lng}`);
413 }
414 return lng;
415 });
416 }
417
418 setLanguage(value: string) {
419 this._set("language", value);

Callers 4

index.tsFile · 0.80
config.test.tsFile · 0.80
initLocalesFunction · 0.80
initMethod · 0.80

Calls 1

_getMethod · 0.95

Tested by

no test coverage detected