Translate admin panel to all 6 languages

This commit is contained in:
openhands committed 2026-07-04 21:21:15 +02:00
1 parent f381aa987f
commit befa4ec282
63 files changed
+9353 -1443

No files matched your search

+43 -42
View File
@@ -3,6 +3,7 @@ import { createApiKey, deleteApiKey, toggleApiKey } from "@/actions/admin-radio-
import { StatusCard } from "@/components/admin/dashboard";
import { prisma } from "@/lib/prisma";
import { Key } from "lucide-react";
import { getTranslations } from "next-intl/server";
export const dynamic = "force-dynamic";
@@ -21,15 +22,16 @@ type ApiKey = {
};
function formatDate(d: Date | null): string {
return d ? d.toISOString().slice(0, 16).replace("T", " ") : "—";
return d ? d.toISOString().slice(0, 16).replace("T", " ") : "\u2014";
}
/** Show only the first 8 chars of the secret; the rest stays masked. */
function maskKey(key: string): string {
return key.length > 8 ? `${key.slice(0, 8)}…` : key;
return key.length > 8 ? `${key.slice(0, 8)}\u2026` : key;
}
export default async function AdminRadioApiKeysPage() {
const t = await getTranslations("pages.admin.radio");
let keys: ApiKey[] = [];
let dbError = false;
@@ -66,13 +68,13 @@ export default async function AdminRadioApiKeysPage() {
return (
<main>
<nav className="text-xs text-gray-500 dark:text-gray-400 mb-2">
<Link href="/admin/radio">Radio</Link> ·{" "}
<Link href="/admin/radio/settings">Settings</Link> ·{" "}
<Link href="/admin/radio/api-keys">API Keys</Link> ·{" "}
<Link href="/admin/radio/autodj">AutoDJ</Link> ·{" "}
<Link href="/admin/radio/embed">Embed</Link> ·{" "}
<Link href="/admin/radio/points">Points</Link> ·{" "}
<Link href="/admin/radio/monitoring">Monitoring</Link>
<Link href="/admin/radio">{t("title")}</Link> ·{" "}
<Link href="/admin/radio/settings">{t("settings")}</Link> ·{" "}
<Link href="/admin/radio/api-keys">{t("apiKeys")}</Link> ·{" "}
<Link href="/admin/radio/autodj">{t("autoDj")}</Link> ·{" "}
<Link href="/admin/radio/embed">{t("embed")}</Link> ·{" "}
<Link href="/admin/radio/points">{t("points")}</Link> ·{" "}
<Link href="/admin/radio/monitoring">{t("monitoring")}</Link>
</nav>
<section className="mt-6">
@@ -81,52 +83,51 @@ export default async function AdminRadioApiKeysPage() {
<Key size={20} className="text-[var(--color-primary)]" />
</div>
<div>
<h1 className="m-0 text-xl font-extrabold text-[var(--color-text)]">Radio API Keys</h1>
<p className="m-0 text-xs text-[var(--color-text-muted)] mt-0.5">API keys for external radio integrations (<code>radio_api_keys</code>). Keys are generated server-side and shown masked — copy the full value from the database when first issued.</p>
<h1 className="m-0 text-xl font-extrabold text-[var(--color-text)]">{t("apiKeysForm.title")}</h1>
<p className="m-0 text-xs text-[var(--color-text-muted)] mt-0.5">{t("apiKeysForm.subtitle")}</p>
</div>
</div>
{dbError ? (
<div className="admin-card" style={{ marginTop: "1rem" }}>
<p className="text-xs text-gray-500 dark:text-gray-400 m-0">
Could not load API keys (database unavailable).
{t("apiKeysForm.dbError")}
</p>
</div>
) : (
<div className="grid grid-cols-[repeat(auto-fit,minmax(180px,1fr))] gap-3.5 mb-6">
<StatusCard label="Total keys" value={total} icon="🔑" />
<StatusCard label={t("apiKeysForm.totalKeys")} value={total} icon="\u{1F511}" />
<StatusCard
label="Active"
label={t("apiKeysForm.active")}
value={activeCount}
state={activeCount > 0 ? "ok" : "neutral"}
icon="✅"
icon="\u{2705}"
/>
<StatusCard
label="Inactive"
label={t("apiKeysForm.inactive")}
value={inactiveCount}
state={inactiveCount > 0 ? "warn" : "neutral"}
icon="🚫"
icon="\u{1F6AB}"
/>
</div>
)}
</section>
<section className="mt-6">
<h2>Generate key</h2>
<h2>{t("apiKeysForm.generateKey")}</h2>
<p className="text-xs text-gray-500 dark:text-gray-400">
The secret key is generated automatically with cryptographic randomness — you do not enter
it.
{t("apiKeysForm.generateHint")}
</p>
<form action={createApiKey} className="admin-card">
<div className="grid cols-2">
<div>
<label htmlFor="new_name" style={{ display: "block", fontWeight: 700 }}>
Name
{t("apiKeysForm.name")}
</label>
<input
id="new_name"
name="name"
placeholder="AzureCast bridge"
placeholder={t("apiKeysForm.namePlaceholder")}
required
maxLength={255}
style={{ width: "100%" }}
@@ -134,7 +135,7 @@ export default async function AdminRadioApiKeysPage() {
</div>
<div>
<label htmlFor="new_rateLimit" style={{ display: "block", fontWeight: 700 }}>
Rate limit (requests/min)
{t("apiKeysForm.rateLimit")}
</label>
<input
id="new_rateLimit"
@@ -147,12 +148,12 @@ export default async function AdminRadioApiKeysPage() {
</div>
<div style={{ gridColumn: "1 / -1" }}>
<label htmlFor="new_allowedIps" style={{ display: "block", fontWeight: 700 }}>
Allowed IPs (optional)
{t("apiKeysForm.allowedIps")}
</label>
<input
id="new_allowedIps"
name="allowedIps"
placeholder="comma-separated, blank = any"
placeholder={t("apiKeysForm.allowedIpsPlaceholder")}
maxLength={255}
style={{ width: "100%" }}
/>
@@ -160,30 +161,30 @@ export default async function AdminRadioApiKeysPage() {
</div>
<div style={{ marginTop: "0.75rem" }}>
<button type="submit" className="btn btn-primary">
Generate key
{t("apiKeysForm.generate")}
</button>
</div>
</form>
</section>
<section className="mt-6">
<h2 className="admin-section-title">Existing keys ({total})</h2>
<h2 className="admin-section-title">{t("apiKeysForm.existingKeys", { count: total })}</h2>
{total === 0 ? (
<div className="admin-empty">No API keys yet — generate one above.</div>
<div className="admin-empty">{t("apiKeysForm.noKeys")}</div>
) : (
<div className="overflow-x-auto">
<table>
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Key</th>
<th>Allowed IPs</th>
<th>Rate limit</th>
<th>Last used</th>
<th>Expires</th>
<th>Status</th>
<th>Actions</th>
<th>{t("apiKeysForm.colName")}</th>
<th>{t("apiKeysForm.colKey")}</th>
<th>{t("apiKeysForm.colAllowedIps")}</th>
<th>{t("apiKeysForm.colRateLimit")}</th>
<th>{t("apiKeysForm.colLastUsed")}</th>
<th>{t("apiKeysForm.colExpires")}</th>
<th>{t("apiKeysForm.colStatus")}</th>
<th>{t("apiKeysForm.colActions")}</th>
</tr>
</thead>
<tbody>
@@ -192,15 +193,15 @@ export default async function AdminRadioApiKeysPage() {
<td className="text-sm text-gray-500 dark:text-gray-400 whitespace-nowrap">{String(k.id)}</td>
<td>{k.name}</td>
<td>
<code title="Only the first 8 characters are shown">{maskKey(k.key)}</code>
<code title={t("apiKeysForm.maskedHint")}>{maskKey(k.key)}</code>
</td>
<td className="text-sm text-gray-500 dark:text-gray-400 whitespace-nowrap">{k.allowedIps || "any"}</td>
<td className="text-sm text-gray-500 dark:text-gray-400 whitespace-nowrap">{k.allowedIps || t("apiKeysForm.any")}</td>
<td className="text-sm text-gray-500 dark:text-gray-400 whitespace-nowrap">{k.rateLimit}/min</td>
<td className="text-sm text-gray-500 dark:text-gray-400 whitespace-nowrap">{formatDate(k.lastUsedAt)}</td>
<td className="text-sm text-gray-500 dark:text-gray-400 whitespace-nowrap">{formatDate(k.expiresAt)}</td>
<td>
<span className={`inline-block text-[0.72rem] font-bold px-2 py-0.5 rounded-full ${k.isActive ? "bg-green-600/20 text-[var(--color-text)]" : "bg-red-500/22 text-[var(--color-text)]"}`}>
{k.isActive ? "active" : "inactive"}
{k.isActive ? t("apiKeysForm.activeLabel") : t("apiKeysForm.inactiveLabel")}
</span>
</td>
<td>
@@ -208,13 +209,13 @@ export default async function AdminRadioApiKeysPage() {
<form action={toggleApiKey}>
<input type="hidden" name="id" value={String(k.id)} />
<button type="submit" className="btn">
{k.isActive ? "Deactivate" : "Activate"}
{k.isActive ? t("apiKeysForm.deactivate") : t("apiKeysForm.activate")}
</button>
</form>
<form action={deleteApiKey}>
<input type="hidden" name="id" value={String(k.id)} />
<button type="submit" className="btn btn-danger">
Delete
{t("apiKeysForm.delete")}
</button>
</form>
</div>