Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
xixixix committed Oct 17, 2023
1 parent d94a1dc commit 9c7d930
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/api/chrome/i18n.ts
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
16 changes: 12 additions & 4 deletions src/i18n/chrome/t.ts
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')
}

0 comments on commit 9c7d930

Please sign in to comment.