mirror of
https://github.com/ReaJason/MemShellParty.git
synced 2026-09-25 00:11:52 +08:00
feat: support fumadocs
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
import i18n from "i18next";
|
||||
import { initReactI18next } from "react-i18next";
|
||||
import commonEN from "@/i18n/common/en.json";
|
||||
import commonZH from "@/i18n/common/zh-CN.json";
|
||||
import memshellEN from "@/i18n/memshell/en.json";
|
||||
import memshellZH from "@/i18n/memshell/zh-CN.json";
|
||||
import probeshellEN from "@/i18n/probeshell/en.json";
|
||||
import probeshellZH from "@/i18n/probeshell/zh-CN.json";
|
||||
|
||||
const getStoredLanguage = () => {
|
||||
if (typeof window === "undefined") {
|
||||
return "zh-CN";
|
||||
}
|
||||
const storedLang = localStorage.getItem("i18nextLng");
|
||||
if (storedLang && ["en", "zh-CN"].includes(storedLang)) {
|
||||
return storedLang;
|
||||
}
|
||||
const browserLang = navigator.language.split("-")[0];
|
||||
return ["en", "zh-CN"].includes(browserLang) ? browserLang : "zh-CN";
|
||||
};
|
||||
|
||||
const fallbackLng = "zh-CN";
|
||||
export const ns = [
|
||||
"default",
|
||||
"common",
|
||||
"memshell",
|
||||
"probeshell",
|
||||
"errors",
|
||||
] as const;
|
||||
export const defaultNS = "default" as const;
|
||||
|
||||
const resources = {
|
||||
"zh-CN": {
|
||||
common: commonZH,
|
||||
memshell: memshellZH,
|
||||
probeshell: probeshellZH,
|
||||
},
|
||||
en: {
|
||||
common: commonEN,
|
||||
memshell: memshellEN,
|
||||
probeshell: probeshellEN,
|
||||
},
|
||||
};
|
||||
|
||||
i18n.use(initReactI18next).init({
|
||||
ns,
|
||||
defaultNS,
|
||||
resources,
|
||||
lng: getStoredLanguage(),
|
||||
fallbackLng,
|
||||
interpolation: {
|
||||
escapeValue: false,
|
||||
},
|
||||
});
|
||||
|
||||
i18n.on("languageChanged", (lng) => {
|
||||
if (typeof window !== "undefined") {
|
||||
localStorage.setItem("i18nextLng", lng);
|
||||
}
|
||||
});
|
||||
|
||||
export default i18n;
|
||||
Reference in New Issue
Block a user