()
| 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); |
no test coverage detected