From 98142e7a79a6ea36bbc0eba1de57487059294fe9 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Sun, 16 Jan 2022 01:09:42 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=8F=92=E4=BB=B6=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0getLanguage=E6=96=B9=E6=B3=95=E7=94=A8=E4=BA=8E?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E8=AF=AD=E8=A8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shared/i18n/index.ts | 7 +++++++ shared/i18n/language.ts | 4 ++-- shared/index.tsx | 8 +++++++- web/src/plugin/common/index.ts | 1 + 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/shared/i18n/index.ts b/shared/i18n/index.ts index c761d42e..858506cf 100644 --- a/shared/i18n/index.ts +++ b/shared/i18n/index.ts @@ -85,6 +85,13 @@ export async function setLanguage(lang: AllowedLanguage): Promise { }); } +/** + * 获取i18n语言 + */ +export function getLanguage(): string { + return i18next.language; +} + /** * 监听语言变更 */ diff --git a/shared/i18n/language.ts b/shared/i18n/language.ts index b3e1f497..44c541ca 100644 --- a/shared/i18n/language.ts +++ b/shared/i18n/language.ts @@ -5,12 +5,12 @@ import { setLanguage as setI18NLanguage } from './index'; import { getStorage, useStorage } from '../manager/storage'; import { LANGUAGE_KEY } from '../utils/consts'; -export const defaultLanguage = 'zh-CN'; +const defaultLanguage = 'zh-CN'; /** * 获取当前语言 */ -export async function getLanguage(): Promise { +async function getLanguage(): Promise { return await getStorage().get(LANGUAGE_KEY, defaultLanguage); } diff --git a/shared/index.tsx b/shared/index.tsx index aaa321dd..fc621ddc 100644 --- a/shared/index.tsx +++ b/shared/index.tsx @@ -53,7 +53,13 @@ export { sharedEvent } from './event/index'; export { getDMConverseName } from './helper/converse-helper'; // i18n -export { t, localTrans, setLanguage, useTranslation } from './i18n'; +export { + t, + localTrans, + setLanguage, + getLanguage, + useTranslation, +} from './i18n'; export { Trans } from './i18n/Trans'; export { useLanguage } from './i18n/language'; diff --git a/web/src/plugin/common/index.ts b/web/src/plugin/common/index.ts index d3b6383b..e2f13057 100644 --- a/web/src/plugin/common/index.ts +++ b/web/src/plugin/common/index.ts @@ -22,6 +22,7 @@ export { getCachedUserInfo, getCachedConverseInfo, localTrans, + getLanguage, sharedEvent, useAsync, useAsyncFn,