mirror of
https://github.com/Corfirean/coa-server-manager.git
synced 2026-11-23 03:25:56 +00:00
Translations: settings schema overlays (ru/de/fr/es), diagnostics, update steps, companion sizes, friends notes; dev mock for settings pages; docs/TRANSLATIONS.md
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a4b9ae81c7
commit
38b5b86be1
22 files changed
+2552
-33
No files matched your search
@@ -3,7 +3,7 @@ import { Loader2 } from "lucide-react";
|
||||
import { api, asUiError, type CompanionSizes, type Population, type UiError } from "@/lib/api";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { useHuman, useT } from "@/i18n";
|
||||
import { hasKey, useHuman, useT, type Key } from "@/i18n";
|
||||
|
||||
export function CompanionsCard({ serverId }: { serverId: string }) {
|
||||
const t = useT();
|
||||
@@ -35,8 +35,15 @@ export function CompanionsCard({ serverId }: { serverId: string }) {
|
||||
};
|
||||
}, [serverId]);
|
||||
|
||||
// The backend describes a size's warning in English; show the translated text for the two known kinds.
|
||||
const warningFor = (size?: { bots: number; warning: string | null }) => {
|
||||
if (!size?.warning) return null;
|
||||
return size.warning.startsWith(`${size.bots} companions`)
|
||||
? t("comp.warnHardware", { n: size.bots, cores: sizes?.hardware.cores ?? "?", ram: sizes ? sizes.hardware.ram_gb.toFixed(0) : "?" })
|
||||
: t("comp.warnMemory");
|
||||
};
|
||||
const count = choice === "custom" ? Number(custom) : (sizes?.sizes.find((s) => s.id === choice)?.bots ?? 0);
|
||||
const warning = choice === "custom" ? (count > 500 ? t("comp.largeWarning") : null) : (sizes?.sizes.find((s) => s.id === choice)?.warning ?? null);
|
||||
const warning = choice === "custom" ? (count > 500 ? t("comp.largeWarning") : null) : (warningFor(sizes?.sizes.find((s) => s.id === choice)));
|
||||
const valid = Number.isInteger(count) && count >= 1 && count <= 2000;
|
||||
|
||||
async function add() {
|
||||
@@ -70,7 +77,7 @@ export function CompanionsCard({ serverId }: { serverId: string }) {
|
||||
{sizes?.sizes.map((s) => (
|
||||
<label key={s.id} className={`cursor-pointer rounded-md border px-3 py-2 text-sm ${choice === s.id ? "border-gold bg-gold/10" : "border-line hover:bg-white/5"}`}>
|
||||
<input type="radio" name="size" className="sr-only" checked={choice === s.id} onChange={() => setChoice(s.id)} />
|
||||
{s.title} <span className="text-muted">· {s.bots}</span>
|
||||
{hasKey(`comp.size.${s.id}`) ? t(`comp.size.${s.id}` as Key) : s.title} <span className="text-muted">· {s.bots}</span>
|
||||
</label>
|
||||
))}
|
||||
<label className={`cursor-pointer rounded-md border px-3 py-2 text-sm ${choice === "custom" ? "border-gold bg-gold/10" : "border-line hover:bg-white/5"}`}>
|
||||
|
||||
@@ -3,12 +3,45 @@ import { Check, Loader2, TriangleAlert, X } from "lucide-react";
|
||||
import { api, asUiError, type DiagCheck, type UiError } from "@/lib/api";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { useHuman, useI18n } from "@/i18n";
|
||||
import { hasKey, useHuman, useI18n, type Key } from "@/i18n";
|
||||
|
||||
const ICON = { ok: Check, warn: TriangleAlert, fail: X } as const;
|
||||
const TONE = { ok: "text-ok", warn: "text-warn", fail: "text-bad" } as const;
|
||||
const WORD = { ok: "diag.word.ok", warn: "diag.word.warn", fail: "diag.word.fail" } as const;
|
||||
|
||||
type T = (k: Key, v?: Record<string, string | number>) => string;
|
||||
|
||||
/** The backend writes each check in English; recognise the known ones and show them in the current language. */
|
||||
function checkText(t: T, c: DiagCheck): { title: string; detail: string } {
|
||||
const title = hasKey(`dg.title.${c.id}`) ? t(`dg.title.${c.id}` as Key) : c.title;
|
||||
const d = c.detail;
|
||||
const rules: [RegExp, (m: RegExpMatchArray) => string][] = [
|
||||
[/^All expected server parts were found\.$/, () => t("dg.files.ok")],
|
||||
[/^Some server parts are missing\.$/, () => t("dg.files.partial")],
|
||||
[/^This is a custom server build; some features are limited\.$/, () => t("dg.files.custom")],
|
||||
[/^This folder does not look like a CoA server\.$/, () => t("dg.files.bad")],
|
||||
[/^Running$/, () => t("dg.svc.running")],
|
||||
[/^Port (\d+) is used by another program \(process (\d+)\)\.$/, (m) => t("dg.svc.port", { port: m[1], pid: m[2] })],
|
||||
[/^Starting, not answering yet\.$/, () => t("dg.svc.starting")],
|
||||
[/^Not running\.$/, () => t("dg.svc.stopped")],
|
||||
[/^Configuration files can be read\.$/, () => t("dg.configs.ok")],
|
||||
[/^Cannot read: (.*)$/, (m) => t("dg.configs.bad", { files: m[1] })],
|
||||
[/^Unusable values for: (.*)$/, (m) => t("dg.values.bad", { keys: m[1] })],
|
||||
[/^(\d+) GB free$/, (m) => t("dg.disk.ok", { gb: m[1] })],
|
||||
[/^Only (\d+) GB free; backups and updates need room\.$/, (m) => t("dg.disk.low", { gb: m[1] })],
|
||||
[/^The server folder is writable\.$/, () => t("dg.perm.ok")],
|
||||
[/^The Manager cannot write to the server folder/, () => t("dg.perm.bad")],
|
||||
[/^The saved game folder was not found; choose it again in Settings\.$/, () => t("dg.client.missing")],
|
||||
[/^Database and server console are not reachable from the network\.$/, () => t("dg.exposure.ok")],
|
||||
[/^Reachable from the network: (.*)\.$/, (m) => t("dg.exposure.bad", { what: m[1] })],
|
||||
];
|
||||
for (const [re, f] of rules) {
|
||||
const m = d.match(re);
|
||||
if (m) return { title, detail: f(m) };
|
||||
}
|
||||
return { title, detail: d };
|
||||
}
|
||||
|
||||
export function DiagnosticsCard({ serverId }: { serverId: string }) {
|
||||
const { t, tn } = useI18n();
|
||||
const human = useHuman();
|
||||
@@ -60,9 +93,9 @@ export function DiagnosticsCard({ serverId }: { serverId: string }) {
|
||||
<li key={c.id + c.title} className="flex items-start gap-3 py-2">
|
||||
<Icon className={`mt-0.5 h-4 w-4 shrink-0 ${TONE[c.level]}`} aria-hidden />
|
||||
<div>
|
||||
<span className="font-medium">{c.title}</span>
|
||||
<span className="font-medium">{checkText(t, c).title}</span>
|
||||
<span className="sr-only"> — {t(WORD[c.level])}</span>
|
||||
<p className="text-muted">{c.detail}</p>
|
||||
<p className="text-muted">{checkText(t, c).detail}</p>
|
||||
</div>
|
||||
</li>
|
||||
);
|
||||
|
||||
@@ -86,7 +86,7 @@ export function FriendsPage({ serverId }: { serverId: string }) {
|
||||
run(`enable-${mode}`, async () => {
|
||||
const r = await api.friendsEnable(serverId, mode, net?.public_ip ?? undefined, mode === "direct" && !!net?.router_found);
|
||||
setNeedsRestart(r.restart_required);
|
||||
return [r.restart_required ? t("fr.restartToApply") : null, r.note].filter(Boolean).join(" ") || t("fr.ready");
|
||||
return [r.restart_required ? t("fr.restartToApply") : null, r.note ? (r.note.startsWith("Your router was asked") ? t("fr.note.forwarded") : r.note.startsWith("Your router does not support") ? t("fr.note.manual") : r.note) : null].filter(Boolean).join(" ") || t("fr.ready");
|
||||
});
|
||||
|
||||
if (!st) return <p className="text-muted">{error ? human(error.human).message : t("fr.looking")}</p>;
|
||||
|
||||
@@ -4,7 +4,7 @@ import { AlertTriangle, Check, Minus } from "lucide-react";
|
||||
import { api, asUiError, type Classification, type ScanReport, type ServerSummary, type UiError } from "@/lib/api";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { useHuman, useT, type Key } from "@/i18n";
|
||||
import { hasKey, useHuman, useT, type Key } from "@/i18n";
|
||||
|
||||
const HEADLINE: Record<Classification, { title: Key; tone: string; text: Key }> = {
|
||||
healthy: { title: "import.healthy.title", tone: "text-ok", text: "import.healthy.text" },
|
||||
@@ -101,7 +101,7 @@ export function ImportServer(props: {
|
||||
<ul className="mt-4 divide-y divide-line text-sm">
|
||||
{report.items.map((it) => (
|
||||
<li key={it.key} className="flex items-center justify-between py-2">
|
||||
<span>{it.label}</span>
|
||||
<span>{hasKey(`scan.label.${it.key}`) ? t(`scan.label.${it.key}` as Key) : it.label}</span>
|
||||
<span className="flex items-center gap-2 text-muted">
|
||||
{it.detail && <span className="text-xs">{it.detail}</span>}
|
||||
{it.status === "found" ? (
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import { useT } from "@/i18n";
|
||||
|
||||
export function Placeholder({ title, question }: { title: string; question: string }) {
|
||||
const t = useT();
|
||||
return (
|
||||
<div className="max-w-xl">
|
||||
<h1 className="text-2xl font-semibold">{title}</h1>
|
||||
<p className="mt-1 text-muted">{question}</p>
|
||||
<p className="mt-8 rounded-card border border-line bg-card/70 p-5 text-sm text-muted">
|
||||
This section is being built in a later release.
|
||||
{t("placeholder.soon")}
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -8,7 +8,7 @@ import { Card } from "@/components/ui/card";
|
||||
import { ClientCard } from "@/screens/ClientCard";
|
||||
import { DiagnosticsCard } from "@/screens/DiagnosticsCard";
|
||||
import { AboutCard } from "@/screens/AboutCard";
|
||||
import { useHuman, useI18n, type Key } from "@/i18n";
|
||||
import { hasKey, useHuman, useI18n, type Key } from "@/i18n";
|
||||
import { LanguagePicker } from "@/components/LanguagePicker";
|
||||
|
||||
function mb(bytes: number) {
|
||||
@@ -192,7 +192,7 @@ export function SettingsHome({ serverId }: { serverId: string }) {
|
||||
{busy === "update" && progress && (
|
||||
<div className="mt-5">
|
||||
<div className="flex justify-between text-sm">
|
||||
<span role="status">{progress.step}</span>
|
||||
<span role="status">{hasKey(`ustep.${progress.step}`) ? t(`ustep.${progress.step}` as Key) : progress.step}</span>
|
||||
<span className="text-muted">{progress.percent}%</span>
|
||||
</div>
|
||||
<div className="mt-2 h-2 overflow-hidden rounded-full bg-white/10" role="progressbar" aria-valuenow={progress.percent} aria-valuemin={0} aria-valuemax={100}>
|
||||
|
||||
@@ -17,16 +17,21 @@ import { cn } from "@/lib/utils";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { CompanionsCard } from "@/screens/CompanionsCard";
|
||||
import { useHuman, useI18n, useT, type Key } from "@/i18n";
|
||||
import { useHuman, useI18n, useSchemaText, useT, type Key } from "@/i18n";
|
||||
|
||||
type T = (k: Key, v?: Record<string, string | number>) => string;
|
||||
|
||||
const RESTART_LABEL = { runtime: "set.restart.runtime", world: "set.restart.world", full: "set.restart.full" } as const;
|
||||
|
||||
function fmt(t: T, v: JsonValue, s: { type: string; unit?: string | null; options: { value: JsonValue; label: string }[] }): string {
|
||||
type SX = ReturnType<typeof useSchemaText>;
|
||||
|
||||
function fmt(t: T, sx: SX, v: JsonValue, s: { key: string; type: string; unit?: string | null; options: { value: JsonValue; label: string }[] }): string {
|
||||
if (typeof v === "boolean") return v ? t("set.on") : t("set.off");
|
||||
if (s.type === "enum") return s.options.find((o) => o.value === v)?.label ?? String(v);
|
||||
return s.unit ? `${v} ${s.unit}` : String(v);
|
||||
if (s.type === "enum") {
|
||||
const o = s.options.find((x) => x.value === v);
|
||||
return o ? sx.option(s.key, o) : String(v);
|
||||
}
|
||||
return s.unit ? `${v} ${sx.unit(s.unit)}` : String(v);
|
||||
}
|
||||
|
||||
function clientCheck(t: T, s: SettingView, v: JsonValue): string | null {
|
||||
@@ -42,6 +47,7 @@ function clientCheck(t: T, s: SettingView, v: JsonValue): string | null {
|
||||
function Field(props: { s: SettingView; value: JsonValue; error: string | null; onChange: (v: JsonValue) => void }) {
|
||||
const { s, value, error, onChange } = props;
|
||||
const t = useT();
|
||||
const sx = useSchemaText();
|
||||
const id = `f-${s.key}`;
|
||||
const base = "rounded-md border bg-bg px-3 py-2 text-sm outline-none focus:border-gold";
|
||||
if (s.type === "bool") {
|
||||
@@ -68,7 +74,7 @@ function Field(props: { s: SettingView; value: JsonValue; error: string | null;
|
||||
>
|
||||
{s.options.map((o) => (
|
||||
<option key={String(o.value)} value={String(o.value)}>
|
||||
{o.label}
|
||||
{sx.option(s.key, o)}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
@@ -88,7 +94,7 @@ function Field(props: { s: SettingView; value: JsonValue; error: string | null;
|
||||
onChange(numeric ? (raw.trim() === "" || Number.isNaN(Number(raw)) ? (raw as unknown as number) : Number(raw)) : raw);
|
||||
}}
|
||||
/>
|
||||
{s.unit && <span className="text-xs text-muted">{s.unit}</span>}
|
||||
{s.unit && <span className="text-xs text-muted">{sx.unit(s.unit)}</span>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -96,12 +102,13 @@ function Field(props: { s: SettingView; value: JsonValue; error: string | null;
|
||||
function Row(props: { s: SettingView; value: JsonValue; error: string | null; onChange: (v: JsonValue) => void; onReset: () => void }) {
|
||||
const { s, value, error } = props;
|
||||
const t = useT();
|
||||
const sx = useSchemaText();
|
||||
const changed = value !== s.value;
|
||||
return (
|
||||
<div className="grid grid-cols-[1fr_auto] items-start gap-x-6 gap-y-1 py-3.5">
|
||||
<div>
|
||||
<label htmlFor={`f-${s.key}`} className="flex flex-wrap items-center gap-2 font-medium">
|
||||
{s.title}
|
||||
{sx.title(s)}
|
||||
{s.dangerous && (
|
||||
<span className="inline-flex items-center gap-1 rounded bg-warn/15 px-1.5 py-0.5 text-[11px] font-normal text-warn">
|
||||
<AlertTriangle className="h-3 w-3" aria-hidden /> {t("set.careful")}
|
||||
@@ -109,9 +116,9 @@ function Row(props: { s: SettingView; value: JsonValue; error: string | null; on
|
||||
)}
|
||||
{changed && <span className="rounded bg-gold/15 px-1.5 py-0.5 text-[11px] font-normal text-gold">{t("set.changed")}</span>}
|
||||
</label>
|
||||
<p className="mt-0.5 max-w-xl text-sm text-muted">{s.description}</p>
|
||||
<p className="mt-0.5 max-w-xl text-sm text-muted">{sx.description(s)}</p>
|
||||
<p className="mt-1 text-xs text-muted/80">
|
||||
{t("set.default", { v: fmt(t, s.default, s) })}
|
||||
{t("set.default", { v: fmt(t, sx, s.default, s) })}
|
||||
{s.min !== undefined && s.max !== undefined && s.type !== "bool" ? ` · ${t("set.range", { min: s.min, max: s.max })}` : ""} · {t(RESTART_LABEL[s.restartRequired])}
|
||||
</p>
|
||||
{s.problem && <p className="mt-1 text-xs text-warn">{t("set.badValue", { problem: s.problem })}</p>}
|
||||
@@ -126,7 +133,7 @@ function Row(props: { s: SettingView; value: JsonValue; error: string | null; on
|
||||
<Field s={s} value={value} error={error} onChange={props.onChange} />
|
||||
<button
|
||||
title={t("set.reset")}
|
||||
aria-label={t("set.resetItem", { name: s.title })}
|
||||
aria-label={t("set.resetItem", { name: sx.title(s) })}
|
||||
onClick={props.onReset}
|
||||
disabled={value === s.default}
|
||||
className="cursor-pointer rounded p-1.5 text-muted hover:bg-white/5 hover:text-ink disabled:opacity-25"
|
||||
@@ -141,6 +148,7 @@ function Row(props: { s: SettingView; value: JsonValue; error: string | null; on
|
||||
export function SettingsPage(props: { serverId: string; scope: Scope; title: string; question: string }) {
|
||||
const { serverId, scope } = props;
|
||||
const { t, tn } = useI18n();
|
||||
const sx = useSchemaText();
|
||||
const human = useHuman();
|
||||
const [view, setView] = useState<SettingsView | null>(null);
|
||||
const [draft, setDraft] = useState<Record<string, JsonValue>>({});
|
||||
@@ -266,8 +274,8 @@ export function SettingsPage(props: { serverId: string; scope: Scope; title: str
|
||||
<div className="mt-5 flex flex-wrap items-center gap-2">
|
||||
<span className="text-sm text-muted">{t("set.presets")}</span>
|
||||
{presets.map((p) => (
|
||||
<Button key={p.id} size="sm" title={p.description} onClick={() => void openPreset(p.id)}>
|
||||
{p.title}
|
||||
<Button key={p.id} size="sm" title={sx.preset(p).description} onClick={() => void openPreset(p.id)}>
|
||||
{sx.preset(p).title}
|
||||
</Button>
|
||||
))}
|
||||
<Button size="sm" variant="ghost" onClick={() => void openPreset("defaults")}>
|
||||
@@ -277,8 +285,8 @@ export function SettingsPage(props: { serverId: string; scope: Scope; title: str
|
||||
|
||||
{preview && (
|
||||
<Card className="mt-4 border-gold/40 p-5">
|
||||
<p className="font-medium">{preview.title}</p>
|
||||
<p className="text-sm text-muted">{preview.description}</p>
|
||||
<p className="font-medium">{sx.preset({ id: preview.id, title: preview.title, description: preview.description }).title}</p>
|
||||
<p className="text-sm text-muted">{sx.preset({ id: preview.id, title: preview.title, description: preview.description }).description}</p>
|
||||
{preview.changes.length === 0 ? (
|
||||
<p className="mt-3 text-sm">{t("set.matches")}</p>
|
||||
) : (
|
||||
@@ -291,9 +299,9 @@ export function SettingsPage(props: { serverId: string; scope: Scope; title: str
|
||||
const s = view.settings.find((x) => x.key === c.key)!;
|
||||
return (
|
||||
<li key={c.key} className="flex justify-between gap-4 py-1.5">
|
||||
<span>{c.title}</span>
|
||||
<span>{sx.title({ key: c.key, title: c.title })}</span>
|
||||
<span className="text-muted">
|
||||
{fmt(t, c.from, s)} → <span className="text-ink">{fmt(t, c.to, s)}</span>
|
||||
{fmt(t, sx, c.from, s)} → <span className="text-ink">{fmt(t, sx, c.to, s)}</span>
|
||||
</span>
|
||||
</li>
|
||||
);
|
||||
@@ -367,7 +375,7 @@ export function SettingsPage(props: { serverId: string; scope: Scope; title: str
|
||||
category === c.id ? "border-gold text-ink" : "border-transparent text-muted hover:text-ink",
|
||||
)}
|
||||
>
|
||||
{c.title}
|
||||
{sx.category(scope, c)}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user