File tree Expand file tree Collapse file tree 2 files changed +15
-7
lines changed Expand file tree Collapse file tree 2 files changed +15
-7
lines changed Original file line number Diff line number Diff line change
1
+ // Bug of chrome:
2
+ // chrome.i18n.getUILanguage may not work in background
1
3
export function getUILanguage ( ) : string {
2
- return chrome . i18n . getUILanguage ( )
4
+ return chrome ? .i18n ? .getUILanguage ?. ( )
3
5
}
4
6
5
- // Bug of chrome:
7
+ // Bug of chrome:
6
8
// chrome.i18n.getMessage may not work in background
7
9
// @see https://stackoverflow.com/questions/6089707/calling-chrome-i18n-getmessage-from-a-content-script
8
- export function getMessage ( messageName : string ) : string {
9
- return chrome . i18n . getMessage ( messageName )
10
- }
10
+ export const getMessage : ( key : string ) => string = chrome ?. i18n ?. getMessage
Original file line number Diff line number Diff line change 6
6
*/
7
7
8
8
import { getMessage } from "@api/chrome/i18n"
9
- import { router , ChromeMessage } from "./message"
9
+ import messages , { router , ChromeMessage } from "./message"
10
+ import { IS_CHROME } from "@util/constant/environment"
11
+ import { t } from ".."
10
12
11
13
export const keyPathOf = ( key : ( root : ChromeMessage ) => string ) => key ( router )
12
14
13
- export const t2Chrome = ( key : ( root : ChromeMessage ) => string ) => getMessage ( keyPathOf ( key ) )
15
+ export const t2Chrome = ( key : ( root : ChromeMessage ) => string ) => {
16
+ if ( getMessage ) {
17
+ return getMessage ( keyPathOf ( key ) )
18
+ }
19
+ console . error ( IS_CHROME )
20
+ return t < ChromeMessage > ( messages , { key } , 'en' )
21
+ }
You can’t perform that action at this time.
0 commit comments