repo_description: A cross-platform desktop All-in-One assistant tool for Claude Code, Codex, OpenCode, openclaw & Gemini CLI.
repo_topics: ai-tools claude-code codex desktop-app mcp minimax omo open-source openclaw openclaw-ui opencode provider-management rust skills skills-management tauri typescript wsl-support
code: import i18n from "i18next";
  import { initReactI18next } from "react-i18next";
  
  import en from "./locales/en.json";
  import ja from "./locales/ja.json";
  import zh from "./locales/zh.json";
  
  type Language = "zh" | "en" | "ja";
  
  const DEFAULT_LANGUAGE: Language = "zh";
  
  const getInitialLanguage = (): Language => {
    if (typeof window !== "undefined") {
      try {
        const stored = window.localStorage.getItem("language");
        if (stored === "zh" || stored === "en" || stored === "ja") {
          return stored;
        }
      } catch (error) {
        console.warn("[i18n] Failed to read stored language preference", error);
      }
    }
  
    const navigatorLang =
      typeof navigator !== "undefined"
        ? (navigator.language?.toLowerCase() ??
          navigator.languages?.[0]?.toLowerCase())
        : undefined;
  
    if (navigatorLang?.startsWith("zh")) {
      return "zh";
    }
  
    if (navigatorLang?.startsWith("ja")) {
      return "ja";
    }
  
    if (navigatorLang?.startsWith("en")) {
      return "en";
    }
  
    return DEFAULT_LANGUAGE;
  };
  
  const resources = {
    en: {
      translation: en,
    },
    ja: {
      translation: ja,
    },
    zh: {
      translation: zh,
    },
  };
  
  i18n.use(initReactI18next).init({
    resources,
    lng: getInitialLanguage(), // 根据本地存储或系统语言选择默认语言
    fallbackLng: "en", // 如果缺少中文翻译则退回英文
  
    interpolation: {
      escapeValue: false, // React 已经默认转义
    },
  
    // 开发模式下显示调试信息
    debug: false,
  });
  
  export default i18n;
  