-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
xixixix
committed
Oct 17, 2023
1 parent
d94a1dc
commit 9c7d930
Showing
2 changed files
with
17 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
// Bug of chrome: | ||
// chrome.i18n.getUILanguage may not work in background | ||
export function getUILanguage(): string { | ||
return chrome.i18n.getUILanguage() | ||
return chrome?.i18n?.getUILanguage?.() | ||
} | ||
|
||
// Bug of chrome: | ||
// Bug of chrome: | ||
// chrome.i18n.getMessage may not work in background | ||
// @see https://stackoverflow.com/questions/6089707/calling-chrome-i18n-getmessage-from-a-content-script | ||
export function getMessage(messageName: string): string { | ||
return chrome.i18n.getMessage(messageName) | ||
} | ||
export const getMessage: (key: string) => string = chrome?.i18n?.getMessage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,21 @@ | ||
/** | ||
* Copyright (c) 2021 Hengyang Zhang | ||
* | ||
* | ||
* This software is released under the MIT License. | ||
* https://opensource.org/licenses/MIT | ||
*/ | ||
|
||
import { getMessage } from "@api/chrome/i18n" | ||
import { router, ChromeMessage } from "./message" | ||
import { getMessage } from '@api/chrome/i18n' | ||
import messages, { router, ChromeMessage } from './message' | ||
import { t } from '..' | ||
import { IS_CHROME } from '@util/constant/environment' | ||
|
||
export const keyPathOf = (key: (root: ChromeMessage) => string) => key(router) | ||
|
||
export const t2Chrome = (key: (root: ChromeMessage) => string) => getMessage(keyPathOf(key)) | ||
export const t2Chrome = (key: (root: ChromeMessage) => string) => { | ||
if (getMessage) { | ||
return getMessage(keyPathOf(key)) | ||
} | ||
console.error(IS_CHROME) | ||
return t<ChromeMessage>(messages, { key }, 'en') | ||
} |