diff --git a/shared/i18n/index.ts b/shared/i18n/index.ts index 6ed489ca..b25f7675 100644 --- a/shared/i18n/index.ts +++ b/shared/i18n/index.ts @@ -58,6 +58,18 @@ export const t: TFunction = ( } }; +/** + * 本地翻译 + * @example + * localTrans({zh-CN: '你好', en-US: 'Hello'}); + * + * @param trans 翻译对象 + */ +export function localTrans(trans: Record) { + const lang = i18next.language as AllowedLanguage; + return trans[lang] ?? trans['zh-CN'] ?? trans['en-US']; +} + /** * 设置i18next的语言 */ diff --git a/shared/index.tsx b/shared/index.tsx index 826460ca..f560671d 100644 --- a/shared/index.tsx +++ b/shared/index.tsx @@ -43,7 +43,7 @@ export { useColorScheme } from './contexts/ColorSchemeContext'; export { getDMConverseName } from './helper/converse-helper'; // i18n -export { t, setLanguage, useTranslation } from './i18n'; +export { t, localTrans, setLanguage, useTranslation } from './i18n'; export { Trans } from './i18n/Trans'; export { useLanguage } from './i18n/language'; diff --git a/web/plugins/com.msgbyte.webview/tsconfig.json b/web/plugins/com.msgbyte.webview/tsconfig.json index beb3c60f..465a28b5 100644 --- a/web/plugins/com.msgbyte.webview/tsconfig.json +++ b/web/plugins/com.msgbyte.webview/tsconfig.json @@ -1,6 +1,5 @@ { "compilerOptions": { - "rootDir": "./src", "baseUrl": "./src", "esModuleInterop": true, "jsx": "react", diff --git a/web/src/plugin/common/index.ts b/web/src/plugin/common/index.ts index 0d377b49..3b0eceb4 100644 --- a/web/src/plugin/common/index.ts +++ b/web/src/plugin/common/index.ts @@ -10,4 +10,8 @@ export { } from '@/routes/Main/Content/Group/utils'; export { openModal, ModalWrapper, useModalContext } from '@/components/Modal'; export { getGlobalState } from '@/utils/global-state-helper'; -export { getCachedUserInfo, getCachedConverseInfo } from 'tailchat-shared'; +export { + getCachedUserInfo, + getCachedConverseInfo, + localTrans, +} from 'tailchat-shared';