index.ts 825 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import i18n from "i18next";
  2. import { getStore } from "../main/storeManage";
  3. import { app } from "electron";
  4. import translation_en from "./resources/en-US";
  5. import translation_zh from "./resources/zh-CN";
  6. const store = getStore();
  7. export const initI18n = () => {
  8. const systemLanguage = app.getLocale();
  9. const language = store.get("language", systemLanguage) as string;
  10. const resources = {
  11. "en-US": {
  12. translation: translation_en,
  13. },
  14. "zh-CN": {
  15. translation: translation_zh,
  16. },
  17. };
  18. i18n.init(
  19. {
  20. resources,
  21. lng: language,
  22. fallbackLng: "en-US",
  23. },
  24. (err) => {
  25. if (err) return console.error("Error loading i18n resources:", err);
  26. console.log("i18n resources loaded successfully");
  27. },
  28. );
  29. };
  30. export const changeLanguage = i18n.changeLanguage;