From abd4f49c4d4e18db205a2948fdca0889b937fe78 Mon Sep 17 00:00:00 2001 From: Craun718 <3653544699@qq.com> Date: Thu, 11 Jun 2026 00:26:50 +0800 Subject: [PATCH] feat(ui): add chinese localization --- packages/ui/src/components/bottom-bar.tsx | 20 +- packages/ui/src/components/config-editor.tsx | 12 +- .../src/components/instance-editor-modal.tsx | 109 ++++---- packages/ui/src/components/login-modal.tsx | 39 ++- packages/ui/src/components/sidebar.tsx | 16 +- packages/ui/src/lib/i18n.tsx | 98 +++++++ packages/ui/src/lib/locales/en.ts | 198 ++++++++++++++ packages/ui/src/lib/locales/zh.ts | 194 ++++++++++++++ packages/ui/src/main.tsx | 7 +- packages/ui/src/models/auth.ts | 27 +- packages/ui/src/models/instance.ts | 24 +- packages/ui/src/models/settings.ts | 3 +- packages/ui/src/pages/home.tsx | 6 +- packages/ui/src/pages/instances/create.tsx | 117 +++++---- packages/ui/src/pages/instances/index.tsx | 47 ++-- packages/ui/src/pages/settings.tsx | 243 +++++++++++------- 16 files changed, 876 insertions(+), 284 deletions(-) create mode 100644 packages/ui/src/lib/i18n.tsx create mode 100644 packages/ui/src/lib/locales/en.ts create mode 100644 packages/ui/src/lib/locales/zh.ts diff --git a/packages/ui/src/components/bottom-bar.tsx b/packages/ui/src/components/bottom-bar.tsx index f73ace46..ad5beb09 100644 --- a/packages/ui/src/components/bottom-bar.tsx +++ b/packages/ui/src/components/bottom-bar.tsx @@ -1,6 +1,7 @@ import { Play, User, XIcon } from "lucide-react"; import { useCallback, useState } from "react"; import { toast } from "sonner"; +import { useI18n } from "@/lib/i18n"; import { cn } from "@/lib/utils"; import { useAuthStore } from "@/models/auth"; import { useGameStore } from "@/models/game"; @@ -18,6 +19,7 @@ import { import { Spinner } from "./ui/spinner"; export function BottomBar() { + const { t } = useI18n(); const account = useAuthStore((state) => state.account); const { instances, activeInstance, setActiveInstance } = useInstanceStore(); @@ -48,15 +50,15 @@ export function BottomBar() { await setActiveInstance(nextInstance); } catch (error) { console.error("Failed to activate instance:", error); - toast.error(`Failed to activate instance: ${String(error)}`); + toast.error(t("bottom.activateFailed", { error: String(error) })); } }, - [activeInstance?.id, instances, setActiveInstance], + [activeInstance?.id, instances, setActiveInstance, t], ); const handleStartGame = async () => { if (!activeInstance) { - toast.info("Please select an instance first!"); + toast.info(t("bottom.selectInstanceFirst")); return; } @@ -77,7 +79,7 @@ export function BottomBar() { size="lg" onClick={() => setShowLoginModal(true)} > - Login + {t("bottom.login")} ); } @@ -90,7 +92,7 @@ export function BottomBar() { disabled={stoppingInstanceId !== null} > {stoppingInstanceId ? : } - Close + {t("bottom.close")} ); } @@ -106,7 +108,7 @@ export function BottomBar() { disabled={launchingInstanceId === activeInstance?.id} > {launchingInstanceId === activeInstance?.id ? : } - Start + {t("bottom.start")} ); }; @@ -133,8 +135,8 @@ export function BottomBar() { @@ -145,7 +147,7 @@ export function BottomBar() {
{instance.name} - {instance.versionId ?? "No version selected"} + {instance.versionId ?? t("bottom.noVersion")}
diff --git a/packages/ui/src/components/config-editor.tsx b/packages/ui/src/components/config-editor.tsx index 129b8f72..b76570c6 100644 --- a/packages/ui/src/components/config-editor.tsx +++ b/packages/ui/src/components/config-editor.tsx @@ -1,6 +1,7 @@ import type React from "react"; import { useEffect, useState } from "react"; import { type ZodType, z } from "zod"; +import { useI18n } from "@/lib/i18n"; import { useSettingsStore } from "@/models/settings"; import type { LauncherConfig } from "@/types"; import { Button } from "./ui/button"; @@ -43,6 +44,7 @@ export interface ConfigEditorProps } export function ConfigEditor({ onOpenChange, ...props }: ConfigEditorProps) { + const { t } = useI18n(); const settings = useSettingsStore(); const [errorMessage, setErrorMessage] = useState(null); @@ -76,10 +78,8 @@ export function ConfigEditor({ onOpenChange, ...props }: ConfigEditorProps) { - Edit Configuration - - Edit the raw JSON configuration file. - + {t("config.title")} + {t("config.desc")}