Skip to content

Commit

Permalink
fix: store languageChanged
Browse files Browse the repository at this point in the history
  • Loading branch information
hamster1963 committed Nov 24, 2024
1 parent a949bf7 commit 17ddce7
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,22 @@ const resources = {
},
};

const getStoredLanguage = () => {
return localStorage.getItem("language") || "zh-CN";
};

i18n.use(initReactI18next).init({
resources,
lng: "zh-CN", // 默认语言
lng: getStoredLanguage(), // 使用localStorage中存储的语言或默认值
fallbackLng: "en", // 当前语言的翻译没有找到时,使用的备选语言
interpolation: {
escapeValue: false, // react已经安全地转义
},
});

// 添加语言改变时的处理函数
i18n.on("languageChanged", (lng) => {
localStorage.setItem("language", lng);
});

export default i18n;

0 comments on commit 17ddce7

Please sign in to comment.