fix(I18n): Translation supplement

Translation supplement, automatic lanSupplement the missing translations
This commit is contained in:
Colin
2024-11-30 13:04:34 +01:00
parent 5c0c358255
commit 63bb672ff1
8 changed files with 34 additions and 31 deletions

View File

@@ -1,5 +1,6 @@
import i18n from "i18next";
import { initReactI18next } from "react-i18next";
import LanguageDetector from "i18next-browser-languagedetector";
import enTranslation from "../locales/en/translation.json";
import itTranslation from "../locales/it/translation.json";
@@ -21,22 +22,16 @@ const resources = {
},
};
const getStoredLanguage = () => {
return localStorage.getItem("language") || "zh-CN";
};
i18n.use(initReactI18next).init({
resources,
lng: getStoredLanguage(), // 使用localStorage中存储的语言或默认值
fallbackLng: "en", // 当前语言的翻译没有找到时,使用的备选语言
interpolation: {
escapeValue: false, // react已经安全地转义
},
});
i18n.use(initReactI18next)
.use(LanguageDetector)
.init({
resources,
fallbackLng: "en", // 当前语言的翻译没有找到时,使用的备选语言
interpolation: {
escapeValue: false, // react已经安全地转义
},
});
// 添加语言改变时的处理函数
i18n.on("languageChanged", (lng) => {
localStorage.setItem("language", lng);
});
export default i18n;