From 048290b49f5f4c08882b1c51a289d31b7f18b590 Mon Sep 17 00:00:00 2001 From: Charles Zhao Date: Sat, 30 Apr 2022 09:36:51 +0800 Subject: [PATCH] feat(console): integrate admin console language settings --- packages/console/src/App.tsx | 6 ++++++ packages/console/src/i18n/init.ts | 5 +++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/console/src/App.tsx b/packages/console/src/App.tsx index 02ef697d7..aafc69200 100644 --- a/packages/console/src/App.tsx +++ b/packages/console/src/App.tsx @@ -53,6 +53,12 @@ const Main = () => { }; }, [data?.adminConsole.appearanceMode]); + useEffect(() => { + (async () => { + void initI18n(data?.adminConsole.language); + })(); + }, [data?.adminConsole.language]); + useEffect(() => { if (location.pathname === '/') { navigate(getPath(sections[0]?.items[0]?.title ?? '')); diff --git a/packages/console/src/i18n/init.ts b/packages/console/src/i18n/init.ts index 142bc4129..79fdadd8a 100644 --- a/packages/console/src/i18n/init.ts +++ b/packages/console/src/i18n/init.ts @@ -1,9 +1,9 @@ -import resources from '@logto/phrases'; +import resources, { Language } from '@logto/phrases'; import i18next from 'i18next'; import LanguageDetector from 'i18next-browser-languagedetector'; import { initReactI18next } from 'react-i18next'; -const initI18n = async () => +const initI18n = async (language?: Language) => i18next .use(initReactI18next) .use(LanguageDetector) @@ -13,6 +13,7 @@ const initI18n = async () => interpolation: { escapeValue: false, }, + lng: language, }); export default initI18n;