The portal in English and Turkish: a catalogue per language, a switcher at the foot of every page, landing.language, Turkish numbers and dates

Every template and handler message in internal/web goes through a JSON
catalogue under internal/web/locales/<code>/, with English as the fallback.
The language is the person's choice (a cookie set by /_lang/{code}), else
Accept-Language, else landing.language. Tests refuse a key some language
lacks, a translation with other arguments than English, and template text
left in English.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ilker ManapandClaude Opus 5.5 committed 2026-10-05 00:12:53 +02:00
1 parent 30f7f3474a
commit 11231d8c2b
113 files changed
+8091 -1981

No files matched your search

+3
View File
@@ -902,3 +902,6 @@ a.sel-link.small { font-size: .78rem; color: var(--muted); margin-left: .4rem; }
.people-detail h3.chart-title { text-transform: none; letter-spacing: 0; color: var(--fg); font-size: .85rem; margin: .2rem 0; }
.people-detail details.edit { display: inline-block; margin-right: 1rem; vertical-align: top; }
.people-detail details.edit[open] { display: block; margin: .5rem 0; }
/* The language switcher at the foot of every page. */
.langs a { color: var(--muted); }
.langs b { font-weight: 600; }
+62 -34
View File
@@ -24,15 +24,42 @@
const panel = root.querySelector(".fm-panel");
const stats = root.querySelector(".fm-stats");
// --- words -------------------------------------------------------------
// What the map says comes from the page, in the page's language: the
// server writes its catalogue's sentences into #fabric-i18n, with {0}, {1}
// where a figure goes. English is kept here for a page that has none, so
// the map still speaks rather than printing keys.
const EN = {
decimal: ".",
map_failed: "The map could not be made: {0}",
not_mapped: "Not mapped yet: the first scan runs within five minutes of a node on this fabric connecting.",
"tier.leaf": "leaf", "tier.spine": "spine", "tier.core": "core", "tier.supercore": "super-core", "tier.n": "tier {0}",
adapters_row: "adapters", ports_used: "{0}/{1} ports", hosts: "{0} hosts", cables_n: "{0} cables, ",
below_rate: "trained below the {0} Gb/s the rest of its kind run at",
adapters_n: "{0} adapters", degraded_n: "{0} degraded cable(s)", rail: "rail {0}", not_ours: "not one of this cluster's nodes",
"dt.tier": "tier", "dt.ports": "ports", "dt.adapters": "adapters", "dt.adapter": "adapter", "dt.rail": "rail",
"dt.leaf": "leaf", "dt.state": "state", "dt.rate": "rate", "dt.sending": "sending", "dt.receiving": "receiving",
cabled: "{0} of {1} cabled", degraded_cables: "Degraded cables", all_good: "Every cable at its expected rate.",
port_to: "port {0} → {1}: {2}", close: "close", open_node: "open {0} →", adapter: "adapter",
"stat.switches": "switches", "stat.adapters": "adapters", "stat.cables": "cables", "stat.degraded": "degraded",
"stat.rails": "rails", "stat.aligned": "aligned", "stat.crossed": "crossed", "stat.sent": "sent now",
};
const S = (() => {
const e = document.getElementById("fabric-i18n");
try { return e ? JSON.parse(e.textContent) : {}; } catch (_) { return {}; }
})();
const T = (k, ...a) => String(S[k] || EN[k] || k).replace(/\{(\d)\}/g, (_, i) => a[+i]);
const fixed = (v, n) => v.toFixed(n).replace(".", S.decimal || EN.decimal);
// --- colours ---------------------------------------------------------
const speedClass = (g) => g >= 800 ? "xdr" : g >= 400 ? "ndr" : g >= 200 ? "hdr" : g >= 100 ? "edr" : "slow";
const railPalette = ["#38bdf8", "#a78bfa", "#34d399", "#fbbf24", "#f472b6", "#fb7185", "#2dd4bf", "#c084fc"];
const fmtBps = (b) => {
const bits = b * 8;
if (bits >= 1e9) return (bits / 1e9).toFixed(1) + " Gb/s";
if (bits >= 1e6) return (bits / 1e6).toFixed(1) + " Mb/s";
if (bits >= 1e3) return (bits / 1e3).toFixed(0) + " kb/s";
return bits.toFixed(0) + " b/s";
if (bits >= 1e9) return fixed(bits / 1e9, 1) + " Gb/s";
if (bits >= 1e6) return fixed(bits / 1e6, 1) + " Mb/s";
if (bits >= 1e3) return fixed(bits / 1e3, 0) + " kb/s";
return fixed(bits, 0) + " b/s";
};
const el = (name, attrs, parent) => {
const e = document.createElementNS(svgNS, name);
@@ -124,8 +151,7 @@
function draw() {
canvas.textContent = "";
if (!data || !data.map) {
const msg = data && data.error ? "The map could not be made: " + data.error
: "Not mapped yet: the first scan runs within five minutes of a node on this fabric connecting.";
const msg = data && data.error ? T("map_failed", data.error) : T("not_mapped");
canvas.innerHTML = '<p class="fm-empty">' + esc(msg) + "</p>";
fillStats();
return;
@@ -151,13 +177,13 @@
viewport = el("g", { class: "fm-viewport" }, svg);
// Tier labels down the left.
const names = { 1: "leaf", 2: "spine", 3: "core", 4: "super-core" };
const names = { 1: T("tier.leaf"), 2: T("tier.spine"), 3: T("tier.core"), 4: T("tier.supercore") };
// Tier names down the left edge, turned on their side so they take no
// room from the leftmost switch.
const label = (y, text) => el("text", { class: "fm-tier",
transform: `translate(${14 * L.fit},${y}) rotate(-90) scale(${L.fit})` }, viewport).textContent = text;
for (let t = L.tiers; t >= 1; t--) label(L.rowY(t), names[t] || "tier " + t);
label(L.rowY(1) + L.gap, "adapters");
for (let t = L.tiers; t >= 1; t--) label(L.rowY(t), names[t] || T("tier.n", t));
label(L.rowY(1) + L.gap, T("adapters_row"));
// Cables, parallel ones bundled.
const bundles = new Map();
@@ -210,12 +236,12 @@
const nodeLayer = el("g", { class: "fm-nodes" }, viewport);
for (const s of map.switches) {
const p = L.pos[s.guid];
const tierName = s.tier >= 3 ? "core" : s.tier === 2 ? "spine" : "leaf";
const g = el("g", { class: "fm-switch t-" + tierName + (touches[s.guid] && touches[s.guid].bad ? " has-bad" : ""),
const tierClass = s.tier >= 3 ? "core" : s.tier === 2 ? "spine" : "leaf";
const g = el("g", { class: "fm-switch t-" + tierClass + (touches[s.guid] && touches[s.guid].bad ? " has-bad" : ""),
transform: `translate(${p.x},${p.y}) scale(${L.swScale})`, tabindex: 0 }, nodeLayer);
el("rect", { x: -56, y: -17, width: 112, height: 34, rx: 10, fill: `url(#fm-g-${tierName})` }, g);
el("rect", { x: -56, y: -17, width: 112, height: 34, rx: 10, fill: `url(#fm-g-${tierClass})` }, g);
el("text", { class: "fm-name", y: -1 }, g).textContent = s.name.length > 16 ? s.name.slice(0, 15) + "…" : s.name;
el("text", { class: "fm-sub", y: 11 }, g).textContent = `${s.used}/${s.ports} ports` + (s.hosts ? ` · ${s.hosts} hosts` : "");
el("text", { class: "fm-sub", y: 11 }, g).textContent = T("ports_used", s.used, s.ports) + (s.hosts ? " · " + T("hosts", s.hosts) : "");
// Port use as an arc along the bottom edge.
const frac = s.ports ? Math.min(1, s.used / s.ports) : 0;
el("line", { x1: -46, y1: 15.5, x2: -46 + 92 * frac, y2: 15.5, class: "fm-use" }, g);
@@ -315,22 +341,24 @@
return s ? s.name : h ? (h.node ? h.node + " " + (h.hca || "") : h.desc) : g; };
const k = b.links[0];
const exp = k.host ? map.expected_host_gbps : map.expected_switch_gbps;
return `<b>${esc(n(b.from))} ↔ ${esc(n(b.to))}</b><br>${b.links.length > 1 ? b.links.length + " cables, " : ""}${esc(k.rate)} · ${k.gbps} Gb/s` +
(b.links.some((x) => x.degraded) ? `<br><span class="fm-bad">trained below the ${exp} Gb/s the rest of its kind run at</span>` : "");
return `<b>${esc(n(b.from))} ↔ ${esc(n(b.to))}</b><br>${b.links.length > 1 ? esc(T("cables_n", b.links.length)) : ""}${esc(k.rate)} · ${k.gbps} Gb/s` +
(b.links.some((x) => x.degraded) ? `<br><span class="fm-bad">${esc(T("below_rate", exp))}</span>` : "");
}
const tierName = (s) => s.tier >= 3 ? T("tier.core") : s.tier === 2 ? T("tier.spine") : T("tier.leaf");
function switchTip(s, map, touches) {
const bad = touches[s.guid] && touches[s.guid].bad;
return `<b>${esc(s.name)}</b><br>${s.tier >= 3 ? "core" : s.tier === 2 ? "spine" : "leaf"} · ${s.used}/${s.ports} ports` +
(s.hosts ? ` · ${s.hosts} adapters` : "") + (s.lid ? ` · LID ${s.lid}` : "") + (bad ? `<br><span class="fm-bad">${bad} degraded cable(s)</span>` : "");
return `<b>${esc(s.name)}</b><br>${esc(tierName(s))} · ${esc(T("ports_used", s.used, s.ports))}` +
(s.hosts ? " · " + esc(T("adapters_n", s.hosts)) : "") + (s.lid ? ` · LID ${s.lid}` : "") +
(bad ? `<br><span class="fm-bad">${esc(T("degraded_n", bad))}</span>` : "");
}
function hostTip(h, live) {
let t = `<b>${esc(h.node || h.desc || h.guid)}</b>${h.hca ? " · " + esc(h.hca) : ""}<br>rail ${h.rail}`;
let t = `<b>${esc(h.node || h.desc || h.guid)}</b>${h.hca ? " · " + esc(h.hca) : ""}<br>${esc(T("rail", h.rail))}`;
if (live) {
t += ` · ${esc(live.state)}${live.gbps ? " · " + live.gbps + " Gb/s" : ""}`;
if (live.tx_bps || live.rx_bps) t += `<br>↑ ${fmtBps(live.tx_bps)} · ↓ ${fmtBps(live.rx_bps)}`;
if (live.errors) t += `<br><span class="fm-bad">${Object.entries(live.errors).map(([k, v]) => esc(k) + " " + v).join(", ")}</span>`;
} else if (!h.node) {
t += "<br><span class=\"fm-dim\">not one of this cluster's nodes</span>";
t += `<br><span class="fm-dim">${esc(T("not_ours"))}</span>`;
}
return t;
}
@@ -338,24 +366,24 @@
const cables = map.links.filter((k) => k.from === s.guid || k.to === s.guid);
const bad = cables.filter((k) => k.degraded);
const rows = bad.map((k) => { const o = k.from === s.guid ? k.to : k.from; const on = map.switches.find((x) => x.guid === o) || map.hosts.find((x) => x.guid === o);
return `<li>port ${k.from === s.guid ? k.from_port : k.to_port} → ${esc(on ? (on.name || on.node || on.desc) : o)}: ${esc(k.rate)}</li>`; }).join("");
return `<button class="fm-close" aria-label="close">×</button><h4>${esc(s.name)}</h4>
<dl><dt>tier</dt><dd>${s.tier >= 3 ? "core" : s.tier === 2 ? "spine" : "leaf"}</dd><dt>GUID</dt><dd><code>${esc(s.guid)}</code></dd>
<dt>LID</dt><dd>${s.lid || "—"}</dd><dt>ports</dt><dd>${s.used} of ${s.ports} cabled</dd><dt>adapters</dt><dd>${s.hosts}</dd></dl>` +
(bad.length ? `<p class="fm-bad">Degraded cables</p><ul>${rows}</ul>` : "<p class=\"fm-dim\">Every cable at its expected rate.</p>");
return `<li>${esc(T("port_to", k.from === s.guid ? k.from_port : k.to_port, on ? (on.name || on.node || on.desc) : o, k.rate))}</li>`; }).join("");
return `<button class="fm-close" aria-label="${esc(T("close"))}">×</button><h4>${esc(s.name)}</h4>
<dl><dt>${esc(T("dt.tier"))}</dt><dd>${esc(tierName(s))}</dd><dt>GUID</dt><dd><code>${esc(s.guid)}</code></dd>
<dt>LID</dt><dd>${s.lid || "—"}</dd><dt>${esc(T("dt.ports"))}</dt><dd>${esc(T("cabled", s.used, s.ports))}</dd><dt>${esc(T("dt.adapters"))}</dt><dd>${s.hosts}</dd></dl>` +
(bad.length ? `<p class="fm-bad">${esc(T("degraded_cables"))}</p><ul>${rows}</ul>` : `<p class="fm-dim">${esc(T("all_good"))}</p>`);
}
function hostPanel(h, live, map) {
const leaf = map.switches.find((x) => x.guid === h.leaf);
let body = `<dl><dt>adapter</dt><dd>${esc(h.hca || h.desc)}</dd><dt>GUID</dt><dd><code>${esc(h.guid)}</code></dd>
<dt>rail</dt><dd>${h.rail}</dd><dt>leaf</dt><dd>${esc(leaf ? leaf.name : "—")}</dd>`;
let body = `<dl><dt>${esc(T("dt.adapter"))}</dt><dd>${esc(h.hca || h.desc)}</dd><dt>GUID</dt><dd><code>${esc(h.guid)}</code></dd>
<dt>${esc(T("dt.rail"))}</dt><dd>${h.rail}</dd><dt>${esc(T("dt.leaf"))}</dt><dd>${esc(leaf ? leaf.name : "—")}</dd>`;
if (live) {
body += `<dt>state</dt><dd>${esc(live.state)} (${esc(live.phys_state)})</dd><dt>rate</dt><dd>${live.gbps} Gb/s</dd>
<dt>sending</dt><dd>${fmtBps(live.tx_bps)}</dd><dt>receiving</dt><dd>${fmtBps(live.rx_bps)}</dd>`;
body += `<dt>${esc(T("dt.state"))}</dt><dd>${esc(live.state)} (${esc(live.phys_state)})</dd><dt>${esc(T("dt.rate"))}</dt><dd>${live.gbps} Gb/s</dd>
<dt>${esc(T("dt.sending"))}</dt><dd>${fmtBps(live.tx_bps)}</dd><dt>${esc(T("dt.receiving"))}</dt><dd>${fmtBps(live.rx_bps)}</dd>`;
}
body += "</dl>";
if (live && live.errors) body += `<p class="fm-bad">${Object.entries(live.errors).map(([k, v]) => esc(k) + " " + v).join("<br>")}</p>`;
const link = h.node ? `<a href="${esc(root.dataset.nodes + "/" + encodeURIComponent(h.node))}">open ${esc(h.node)} →</a>` : "";
return `<button class="fm-close" aria-label="close">×</button><h4>${esc(h.node || h.desc || "adapter")}</h4>${body}${link}`;
const link = h.node ? `<a href="${esc(root.dataset.nodes + "/" + encodeURIComponent(h.node))}">${esc(T("open_node", h.node))}</a>` : "";
return `<button class="fm-close" aria-label="${esc(T("close"))}">×</button><h4>${esc(h.node || h.desc || T("adapter"))}</h4>${body}${link}`;
}
panel.addEventListener("click", (e) => {
if (e.target.classList.contains("fm-close")) { panel.hidden = true; state.selected = null; unhighlight(); }
@@ -405,11 +433,11 @@
const tx = live.reduce((a, l) => a + (l.tx_bps || 0), 0);
const cells = [];
if (m) {
cells.push([m.switches.length, "switches"], [m.hosts.length, "adapters"], [m.links.length, "cables"],
[m.degraded, "degraded", m.degraded ? "bad" : "ok"],
[m.rails.length > 1 ? (m.rail_aligned ? "aligned" : "crossed") : "—", "rails", m.rails.length > 1 && !m.rail_aligned ? "bad" : ""]);
cells.push([m.switches.length, T("stat.switches")], [m.hosts.length, T("stat.adapters")], [m.links.length, T("stat.cables")],
[m.degraded, T("stat.degraded"), m.degraded ? "bad" : "ok"],
[m.rails.length > 1 ? (m.rail_aligned ? T("stat.aligned") : T("stat.crossed")) : "—", T("stat.rails"), m.rails.length > 1 && !m.rail_aligned ? "bad" : ""]);
}
cells.push([fmtBps(tx), "sent now"]);
cells.push([fmtBps(tx), T("stat.sent")]);
stats.innerHTML = cells.map(([v, k, c]) => `<div class="fm-stat ${c || ""}"><b>${esc(v)}</b><span>${esc(k)}</span></div>`).join("");
}