feat: support i18n [skip ci]

This commit is contained in:
ReaJason
2025-01-20 00:34:10 +08:00
parent f78c83d901
commit 9154b1b46c
19 changed files with 578 additions and 215 deletions
+32
View File
@@ -0,0 +1,32 @@
import i18n from "i18next";
import { initReactI18next } from "react-i18next";
import { resources } from "./translations";
const getStoredLanguage = () => {
const storedLang = localStorage.getItem("i18nextLng");
if (storedLang && ["en", "zh"].includes(storedLang)) {
return storedLang;
}
const browserLang = navigator.language.split("-")[0];
return ["en", "zh"].includes(browserLang) ? browserLang : "en";
};
i18n.use(initReactI18next).init({
resources,
lng: getStoredLanguage(),
fallbackLng: "en",
interpolation: {
escapeValue: false,
},
detection: {
order: ["localStorage", "navigator"],
},
saveMissing: true,
load: "languageOnly",
});
i18n.on("languageChanged", (lng) => {
localStorage.setItem("i18nextLng", lng);
});
export default i18n;