mirror of
https://github.com/woodchen-ink/nezha-dash-v1.git
synced 2025-07-18 17:41:56 +08:00
fix: store languageChanged
This commit is contained in:
parent
a949bf7e03
commit
17ddce7b0e
11
src/i18n.js
11
src/i18n.js
@ -17,13 +17,22 @@ const resources = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getStoredLanguage = () => {
|
||||||
|
return localStorage.getItem("language") || "zh-CN";
|
||||||
|
};
|
||||||
|
|
||||||
i18n.use(initReactI18next).init({
|
i18n.use(initReactI18next).init({
|
||||||
resources,
|
resources,
|
||||||
lng: "zh-CN", // 默认语言
|
lng: getStoredLanguage(), // 使用localStorage中存储的语言或默认值
|
||||||
fallbackLng: "en", // 当前语言的翻译没有找到时,使用的备选语言
|
fallbackLng: "en", // 当前语言的翻译没有找到时,使用的备选语言
|
||||||
interpolation: {
|
interpolation: {
|
||||||
escapeValue: false, // react已经安全地转义
|
escapeValue: false, // react已经安全地转义
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 添加语言改变时的处理函数
|
||||||
|
i18n.on("languageChanged", (lng) => {
|
||||||
|
localStorage.setItem("language", lng);
|
||||||
|
});
|
||||||
|
|
||||||
export default i18n;
|
export default i18n;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user