From b37e2580ffa6be46e44824ca167cf6e143d8dd62 Mon Sep 17 00:00:00 2001 From: warjiang <1096409085@qq.com> Date: Sat, 18 Jan 2025 21:09:14 +0800 Subject: [PATCH] feat: set default language for i18n Signed-off-by: warjiang <1096409085@qq.com> --- ui/apps/dashboard/src/main.tsx | 85 +++++++++++++++++----------------- 1 file changed, 42 insertions(+), 43 deletions(-) diff --git a/ui/apps/dashboard/src/main.tsx b/ui/apps/dashboard/src/main.tsx index d614bf56..3bb1bc0d 100644 --- a/ui/apps/dashboard/src/main.tsx +++ b/ui/apps/dashboard/src/main.tsx @@ -1,57 +1,56 @@ import React from 'react'; import ReactDOM from 'react-dom/client'; import App from './App.tsx'; -import i18nInstance, {getLang} from '@/utils/i18n'; -import {initReactI18next} from 'react-i18next'; -import {loader} from '@monaco-editor/react'; +import i18nInstance, { getLang } from '@/utils/i18n'; +import { initReactI18next } from 'react-i18next'; +import { loader } from '@monaco-editor/react'; import * as monaco from 'monaco-editor'; import editorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker'; // https://github.com/remcohaszing/monaco-yaml/issues/150 import yamlWorker from '@/utils/workaround-yaml.worker?worker'; import enTexts from '../locales/en-US.json'; import zhTexts from '../locales/zh-CN.json'; -import {initRoute} from '@/routes/route.tsx'; +import { initRoute } from '@/routes/route.tsx'; window.MonacoEnvironment = { - getWorker(_, label) { - if (label === 'yaml') { - return new yamlWorker(); - } - return new editorWorker(); - }, + getWorker(_, label) { + if (label === 'yaml') { + return new yamlWorker(); + } + return new editorWorker(); + }, }; -loader.config({monaco}); +loader.config({ monaco }); i18nInstance - .use(initReactI18next) // passes i18n down to react-i18next - .init({ - debug: true, - lng: getLang(), // if you're using a language detector, do not define the lng option - fallbackLng: ['zh-CN'], - resources: { - zh: { - translation: zhTexts, - }, - en: { - translation: enTexts, - }, - }, - interpolation: { - escapeValue: false, // react already safes from xss => https://www.i18next.com/translation-function/interpolation#unescape - }, - saveMissing: true, // send not translated keys to endpoint, - react: { - useSuspense: false, - }, - }) - .then(() => { - initRoute(); - ReactDOM.createRoot(document.getElementById('root')!).render( - - - , - ); - }) - .catch(() => { - - }) + .use(initReactI18next) // passes i18n down to react-i18next + .init({ + debug: true, + lng: getLang(), // if you're using a language detector, do not define the lng option + // fallbackLng: ['zh-CN'], + fallbackLng: ['en-US'], + resources: { + zh: { + translation: zhTexts, + }, + en: { + translation: enTexts, + }, + }, + interpolation: { + escapeValue: false, // react already safes from xss => https://www.i18next.com/translation-function/interpolation#unescape + }, + saveMissing: true, // send not translated keys to endpoint, + react: { + useSuspense: false, + }, + }) + .then(() => { + initRoute(); + ReactDOM.createRoot(document.getElementById('root')!).render( + + + , + ); + }) + .catch(() => {});