修复web服务页面未处理多语言

This commit is contained in:
xintaofei
2026-03-27 20:49:56 +08:00
parent 31a8195ebd
commit f50c85ce84
11 changed files with 224 additions and 16 deletions

View File

@@ -2,6 +2,7 @@
import { useCallback, useEffect, useState } from "react" import { useCallback, useEffect, useState } from "react"
import { Check, Copy, ExternalLink, Eye, EyeOff } from "lucide-react" import { Check, Copy, ExternalLink, Eye, EyeOff } from "lucide-react"
import { useTranslations } from "next-intl"
import { import {
startWebServer, startWebServer,
stopWebServer, stopWebServer,
@@ -11,6 +12,7 @@ import {
import { openUrl } from "@/lib/platform" import { openUrl } from "@/lib/platform"
function AddressCard({ label, value }: { label: string; value: string }) { function AddressCard({ label, value }: { label: string; value: string }) {
const t = useTranslations("WebServiceSettings")
return ( return (
<div className="space-y-1.5"> <div className="space-y-1.5">
<div className="text-xs font-medium text-muted-foreground">{label}</div> <div className="text-xs font-medium text-muted-foreground">{label}</div>
@@ -23,7 +25,7 @@ function AddressCard({ label, value }: { label: string; value: string }) {
type="button" type="button"
onClick={() => openUrl(value)} onClick={() => openUrl(value)}
className="inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:bg-accent hover:text-accent-foreground" className="inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:bg-accent hover:text-accent-foreground"
title="打开" title={t("open")}
> >
<ExternalLink className="h-3.5 w-3.5" /> <ExternalLink className="h-3.5 w-3.5" />
</button> </button>
@@ -34,6 +36,7 @@ function AddressCard({ label, value }: { label: string; value: string }) {
} }
function TokenCard({ label, value }: { label: string; value: string }) { function TokenCard({ label, value }: { label: string; value: string }) {
const t = useTranslations("WebServiceSettings")
const [copied, setCopied] = useState(false) const [copied, setCopied] = useState(false)
const [revealed, setRevealed] = useState(false) const [revealed, setRevealed] = useState(false)
@@ -59,7 +62,7 @@ function TokenCard({ label, value }: { label: string; value: string }) {
type="button" type="button"
onClick={() => setRevealed((v) => !v)} onClick={() => setRevealed((v) => !v)}
className="inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:bg-accent hover:text-accent-foreground" className="inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:bg-accent hover:text-accent-foreground"
title={revealed ? "隐藏" : "显示"} title={revealed ? t("hide") : t("show")}
> >
{revealed ? ( {revealed ? (
<EyeOff className="h-3.5 w-3.5" /> <EyeOff className="h-3.5 w-3.5" />
@@ -71,7 +74,7 @@ function TokenCard({ label, value }: { label: string; value: string }) {
type="button" type="button"
onClick={handleCopy} onClick={handleCopy}
className="inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:bg-accent hover:text-accent-foreground" className="inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:bg-accent hover:text-accent-foreground"
title="复制" title={t("copy")}
> >
{copied ? ( {copied ? (
<Check className="h-3.5 w-3.5 text-green-500" /> <Check className="h-3.5 w-3.5 text-green-500" />
@@ -86,6 +89,7 @@ function TokenCard({ label, value }: { label: string; value: string }) {
} }
export function WebServiceSettings() { export function WebServiceSettings() {
const t = useTranslations("WebServiceSettings")
const [status, setStatus] = useState<WebServerInfo | null>(null) const [status, setStatus] = useState<WebServerInfo | null>(null)
const [port, setPort] = useState("3080") const [port, setPort] = useState("3080")
const [loading, setLoading] = useState(false) const [loading, setLoading] = useState(false)
@@ -119,7 +123,7 @@ export function WebServiceSettings() {
const msg = const msg =
e && typeof e === "object" && "message" in e e && typeof e === "object" && "message" in e
? (e as { message: string }).message ? (e as { message: string }).message
: "启动失败" : t("startFailed")
setError(msg) setError(msg)
} finally { } finally {
setLoading(false) setLoading(false)
@@ -132,7 +136,7 @@ export function WebServiceSettings() {
await stopWebServer() await stopWebServer()
setStatus(null) setStatus(null)
} catch { } catch {
setError("停止失败") setError(t("stopFailed"))
} finally { } finally {
setLoading(false) setLoading(false)
} }
@@ -143,16 +147,16 @@ export function WebServiceSettings() {
return ( return (
<div className="space-y-6"> <div className="space-y-6">
<div> <div>
<h3 className="text-lg font-medium">Web </h3> <h3 className="text-lg font-medium">{t("sectionTitle")}</h3>
<p className="text-sm text-muted-foreground"> <p className="text-sm text-muted-foreground">
访 Codeg {t("sectionDescription")}
</p> </p>
</div> </div>
<div className="space-y-4"> <div className="space-y-4">
{/* Port config */} {/* Port config */}
<div className="flex items-center gap-4"> <div className="flex items-center gap-4">
<label className="w-20 text-sm font-medium"></label> <label className="w-20 text-sm font-medium">{t("port")}</label>
<input <input
type="number" type="number"
value={port} value={port}
@@ -166,20 +170,22 @@ export function WebServiceSettings() {
{/* Start/Stop button */} {/* Start/Stop button */}
<div className="flex items-center gap-4"> <div className="flex items-center gap-4">
<label className="w-20 text-sm font-medium"></label> <label className="w-20 text-sm font-medium">{t("status")}</label>
<div className="flex items-center gap-3"> <div className="flex items-center gap-3">
<span <span
className={`inline-block h-2 w-2 rounded-full ${ className={`inline-block h-2 w-2 rounded-full ${
isRunning ? "bg-green-500" : "bg-muted-foreground/30" isRunning ? "bg-green-500" : "bg-muted-foreground/30"
}`} }`}
/> />
<span className="text-sm">{isRunning ? "运行中" : "已停止"}</span> <span className="text-sm">
{isRunning ? t("running") : t("stopped")}
</span>
<button <button
onClick={isRunning ? handleStop : handleStart} onClick={isRunning ? handleStop : handleStart}
disabled={loading} disabled={loading}
className="inline-flex h-8 items-center rounded-md border border-input bg-background px-3 text-xs font-medium ring-offset-background transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50" className="inline-flex h-8 items-center rounded-md border border-input bg-background px-3 text-xs font-medium ring-offset-background transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50"
> >
{loading ? "处理中..." : isRunning ? "停止" : "启动"} {loading ? t("processing") : isRunning ? t("stop") : t("start")}
</button> </button>
</div> </div>
</div> </div>
@@ -190,12 +196,14 @@ export function WebServiceSettings() {
{isRunning && ( {isRunning && (
<div className="space-y-3"> <div className="space-y-3">
{status.addresses.map((addr) => ( {status.addresses.map((addr) => (
<AddressCard key={addr} label="访问地址" value={addr} /> <AddressCard
key={addr}
label={t("addressLabel")}
value={addr}
/>
))} ))}
<TokenCard label="访问 Token" value={status.token} /> <TokenCard label={t("tokenLabel")} value={status.token} />
<p className="text-xs text-muted-foreground"> <p className="text-xs text-muted-foreground">{t("tokenHint")}</p>
Web 访 Token
</p>
</div> </div>
)} )}
</div> </div>

View File

@@ -1630,5 +1630,25 @@
"directoryExists": "الدليل الهدف موجود بالفعل", "directoryExists": "الدليل الهدف موجود بالفعل",
"commandFailed": "فشل أمر إنشاء المشروع." "commandFailed": "فشل أمر إنشاء المشروع."
} }
},
"WebServiceSettings": {
"sectionTitle": "خدمة الويب",
"sectionDescription": "تفعيل للوصول إلى Codeg عن بُعد عبر المتصفح",
"port": "المنفذ",
"status": "الحالة",
"running": "قيد التشغيل",
"stopped": "متوقف",
"processing": "جارٍ المعالجة...",
"start": "تشغيل",
"stop": "إيقاف",
"startFailed": "فشل التشغيل",
"stopFailed": "فشل الإيقاف",
"open": "فتح",
"hide": "إخفاء",
"show": "إظهار",
"copy": "نسخ",
"addressLabel": "عنوان الوصول",
"tokenLabel": "رمز الوصول",
"tokenHint": "أدخل هذا الرمز عند الوصول إلى عميل الويب لأول مرة"
} }
} }

View File

@@ -1630,5 +1630,25 @@
"directoryExists": "Zielverzeichnis existiert bereits", "directoryExists": "Zielverzeichnis existiert bereits",
"commandFailed": "Projekterstellungsbefehl fehlgeschlagen." "commandFailed": "Projekterstellungsbefehl fehlgeschlagen."
} }
},
"WebServiceSettings": {
"sectionTitle": "Webdienst",
"sectionDescription": "Aktivieren Sie den Fernzugriff auf Codeg über den Browser",
"port": "Port",
"status": "Status",
"running": "Läuft",
"stopped": "Gestoppt",
"processing": "Verarbeitung...",
"start": "Starten",
"stop": "Stoppen",
"startFailed": "Start fehlgeschlagen",
"stopFailed": "Stopp fehlgeschlagen",
"open": "Öffnen",
"hide": "Ausblenden",
"show": "Einblenden",
"copy": "Kopieren",
"addressLabel": "Zugriffsadresse",
"tokenLabel": "Zugriffstoken",
"tokenHint": "Geben Sie dieses Token beim ersten Zugriff auf den Web-Client ein"
} }
} }

View File

@@ -1630,5 +1630,25 @@
"directoryExists": "Target directory already exists", "directoryExists": "Target directory already exists",
"commandFailed": "Project creation command failed." "commandFailed": "Project creation command failed."
} }
},
"WebServiceSettings": {
"sectionTitle": "Web Service",
"sectionDescription": "Enable to access Codeg remotely via browser",
"port": "Port",
"status": "Status",
"running": "Running",
"stopped": "Stopped",
"processing": "Processing...",
"start": "Start",
"stop": "Stop",
"startFailed": "Failed to start",
"stopFailed": "Failed to stop",
"open": "Open",
"hide": "Hide",
"show": "Show",
"copy": "Copy",
"addressLabel": "Access Address",
"tokenLabel": "Access Token",
"tokenHint": "Enter this token when accessing the Web client for the first time"
} }
} }

View File

@@ -1630,5 +1630,25 @@
"directoryExists": "El directorio de destino ya existe", "directoryExists": "El directorio de destino ya existe",
"commandFailed": "El comando de creación del proyecto falló." "commandFailed": "El comando de creación del proyecto falló."
} }
},
"WebServiceSettings": {
"sectionTitle": "Servicio Web",
"sectionDescription": "Habilitar para acceder a Codeg de forma remota a través del navegador",
"port": "Puerto",
"status": "Estado",
"running": "En ejecución",
"stopped": "Detenido",
"processing": "Procesando...",
"start": "Iniciar",
"stop": "Detener",
"startFailed": "Error al iniciar",
"stopFailed": "Error al detener",
"open": "Abrir",
"hide": "Ocultar",
"show": "Mostrar",
"copy": "Copiar",
"addressLabel": "Dirección de acceso",
"tokenLabel": "Token de acceso",
"tokenHint": "Ingrese este token al acceder al cliente Web por primera vez"
} }
} }

View File

@@ -1630,5 +1630,25 @@
"directoryExists": "Le répertoire cible existe déjà", "directoryExists": "Le répertoire cible existe déjà",
"commandFailed": "La commande de création du projet a échoué." "commandFailed": "La commande de création du projet a échoué."
} }
},
"WebServiceSettings": {
"sectionTitle": "Service Web",
"sectionDescription": "Activer pour accéder à Codeg à distance via le navigateur",
"port": "Port",
"status": "Statut",
"running": "En cours",
"stopped": "Arrêté",
"processing": "Traitement...",
"start": "Démarrer",
"stop": "Arrêter",
"startFailed": "Échec du démarrage",
"stopFailed": "Échec de l'arrêt",
"open": "Ouvrir",
"hide": "Masquer",
"show": "Afficher",
"copy": "Copier",
"addressLabel": "Adresse d'accès",
"tokenLabel": "Token d'accès",
"tokenHint": "Entrez ce token lors du premier accès au client Web"
} }
} }

View File

@@ -1630,5 +1630,25 @@
"directoryExists": "対象ディレクトリは既に存在します", "directoryExists": "対象ディレクトリは既に存在します",
"commandFailed": "プロジェクト作成コマンドが失敗しました。" "commandFailed": "プロジェクト作成コマンドが失敗しました。"
} }
},
"WebServiceSettings": {
"sectionTitle": "Webサービス",
"sectionDescription": "有効にするとブラウザからCodegにリモートアクセスできます",
"port": "ポート",
"status": "ステータス",
"running": "実行中",
"stopped": "停止中",
"processing": "処理中...",
"start": "開始",
"stop": "停止",
"startFailed": "開始に失敗しました",
"stopFailed": "停止に失敗しました",
"open": "開く",
"hide": "非表示",
"show": "表示",
"copy": "コピー",
"addressLabel": "アクセスアドレス",
"tokenLabel": "アクセストークン",
"tokenHint": "Webクライアントの初回アクセス時にこのトークンを入力してください"
} }
} }

View File

@@ -1630,5 +1630,25 @@
"directoryExists": "대상 디렉터리가 이미 존재합니다", "directoryExists": "대상 디렉터리가 이미 존재합니다",
"commandFailed": "프로젝트 생성 명령이 실패했습니다." "commandFailed": "프로젝트 생성 명령이 실패했습니다."
} }
},
"WebServiceSettings": {
"sectionTitle": "웹 서비스",
"sectionDescription": "활성화하면 브라우저를 통해 Codeg에 원격으로 접속할 수 있습니다",
"port": "포트",
"status": "상태",
"running": "실행 중",
"stopped": "중지됨",
"processing": "처리 중...",
"start": "시작",
"stop": "중지",
"startFailed": "시작 실패",
"stopFailed": "중지 실패",
"open": "열기",
"hide": "숨기기",
"show": "표시",
"copy": "복사",
"addressLabel": "접속 주소",
"tokenLabel": "접속 토큰",
"tokenHint": "웹 클라이언트 첫 접속 시 이 토큰을 입력하세요"
} }
} }

View File

@@ -1630,5 +1630,25 @@
"directoryExists": "O diretório de destino já existe", "directoryExists": "O diretório de destino já existe",
"commandFailed": "O comando de criação do projeto falhou." "commandFailed": "O comando de criação do projeto falhou."
} }
},
"WebServiceSettings": {
"sectionTitle": "Serviço Web",
"sectionDescription": "Ativar para acessar o Codeg remotamente pelo navegador",
"port": "Porta",
"status": "Status",
"running": "Em execução",
"stopped": "Parado",
"processing": "Processando...",
"start": "Iniciar",
"stop": "Parar",
"startFailed": "Falha ao iniciar",
"stopFailed": "Falha ao parar",
"open": "Abrir",
"hide": "Ocultar",
"show": "Mostrar",
"copy": "Copiar",
"addressLabel": "Endereço de acesso",
"tokenLabel": "Token de acesso",
"tokenHint": "Insira este token ao acessar o cliente Web pela primeira vez"
} }
} }

View File

@@ -1630,5 +1630,25 @@
"directoryExists": "目标目录已存在", "directoryExists": "目标目录已存在",
"commandFailed": "项目创建命令执行失败。" "commandFailed": "项目创建命令执行失败。"
} }
},
"WebServiceSettings": {
"sectionTitle": "Web 服务",
"sectionDescription": "启用后可通过浏览器远程访问 Codeg",
"port": "端口",
"status": "状态",
"running": "运行中",
"stopped": "已停止",
"processing": "处理中...",
"start": "启动",
"stop": "停止",
"startFailed": "启动失败",
"stopFailed": "停止失败",
"open": "打开",
"hide": "隐藏",
"show": "显示",
"copy": "复制",
"addressLabel": "访问地址",
"tokenLabel": "访问 Token",
"tokenHint": "Web 客户端首次访问时需输入此 Token"
} }
} }

View File

@@ -1630,5 +1630,25 @@
"directoryExists": "目標目錄已存在", "directoryExists": "目標目錄已存在",
"commandFailed": "專案建立命令執行失敗。" "commandFailed": "專案建立命令執行失敗。"
} }
},
"WebServiceSettings": {
"sectionTitle": "Web 服務",
"sectionDescription": "啟用後可透過瀏覽器遠端存取 Codeg",
"port": "連接埠",
"status": "狀態",
"running": "執行中",
"stopped": "已停止",
"processing": "處理中...",
"start": "啟動",
"stop": "停止",
"startFailed": "啟動失敗",
"stopFailed": "停止失敗",
"open": "開啟",
"hide": "隱藏",
"show": "顯示",
"copy": "複製",
"addressLabel": "存取位址",
"tokenLabel": "存取 Token",
"tokenHint": "Web 用戶端首次存取時需輸入此 Token"
} }
} }