From 3d34185171fb49dd0a514bc00ead7e82bbea39af Mon Sep 17 00:00:00 2001 From: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com> Date: Sun, 11 Oct 2026 06:38:07 +0000 Subject: [PATCH] refactor(website): move UI text out of scripts before translation Prepare the website for localized pages without changing what English readers see: - Add --font-sans and --font-mono tokens and use them for every font stack. - Read copy feedback from the shared #copy-status element, restore each Copy button's own label, and build the GitHub star label from header data attributes with Intl.PluralRules and Intl.NumberFormat for the page language. - Move the percent demo, dinosaur game and speed-check messages into data-msg-* attributes on the home page and dino lab. - Render the skip link from the shared header template. - Fix the lowercase Ghidra macOS/Linux copy-button label. Co-Authored-By: Claude Opus 5.5 --- website/README.md | 7 ++- website/public/assets/dino-demo.js | 50 +++++++++++-------- website/public/assets/home.js | 11 ++-- website/public/assets/main.js | 29 +++++++---- website/public/assets/styles.css | 16 +++--- website/public/blog/index.html | 16 +++++- .../blog/touhou-reconstruction/index.html | 16 +++++- website/public/examples/dino-lab/index.html | 43 ++++++++++++++-- website/public/faq/index.html | 16 +++++- website/public/first-investigation/index.html | 16 +++++- website/public/get-started/index.html | 18 +++++-- website/public/guides/browser/index.html | 16 +++++- website/public/guides/index.html | 16 +++++- website/public/guides/javascript/index.html | 16 +++++- website/public/guides/native/index.html | 16 +++++- website/public/index.html | 44 ++++++++++++++-- website/public/showcase/aegis/index.html | 16 +++++- website/public/showcase/ctf/index.html | 16 +++++- website/public/showcase/dx-ball/index.html | 16 +++++- website/public/showcase/index.html | 16 +++++- website/public/showcase/notion/index.html | 16 +++++- website/public/showcase/th04/index.html | 16 +++++- website/templates/footer.html.tmpl | 11 +++- website/templates/header.html.tmpl | 4 ++ website/templates/page.html | 1 - 25 files changed, 372 insertions(+), 86 deletions(-) diff --git a/website/README.md b/website/README.md index bcd3ce5bc..cc28319b6 100644 --- a/website/README.md +++ b/website/README.md @@ -7,8 +7,11 @@ An English static website with explanatory figures, worked guides and Aegis, DX-Ball, Notion, TH04 and CTF investigations. The public files are in `website/public/`. The site uses HTML, CSS and small scripts for copying code, following code comparisons and playing the dinosaur -speed reconstruction. Small Python commands maintain shared HTML, prepare -downloads and check the site. There is no frontend framework, bundler or npm +speed reconstruction. The scripts contain no reader-facing text: copy messages +and the GitHub star label come from the shared header and footer, and each demo +reads its messages from `data-msg-*` attributes in the page, with `{name}` +placeholders for inserted values. Small Python commands maintain shared HTML, +prepare downloads and check the site. There is no frontend framework, bundler or npm dependency. The checked-in HTML works as ordinary static files. [style-guide.md](style-guide.md) explains the writing, page structure, figures, diff --git a/website/public/assets/dino-demo.js b/website/public/assets/dino-demo.js index 9988e9f52..4622685c3 100644 --- a/website/public/assets/dino-demo.js +++ b/website/public/assets/dino-demo.js @@ -11,6 +11,9 @@ function initializeDinoDemo(demo) { const auto = demo.querySelector("[data-dino-auto]"); const output = demo.querySelector("[data-dino-speed]"); const status = demo.querySelector("[data-dino-status]"); + // The page owns the localized messages; {name} marks an inserted value. + const message = (name, values = {}) => + demo.dataset[name].replace(/\{(\w+)\}/g, (_, key) => values[key]); const ground = 148; const dinosaurX = 52; const dinosaur = new Path2D( @@ -67,7 +70,9 @@ function initializeDinoDemo(demo) { context.font = "13px monospace"; context.textAlign = "right"; context.fillText( - `DISTANCE ${String(Math.floor(distance / 100)).padStart(4, "0")}`, + message("msgDistance", { + distance: String(Math.floor(distance / 100)).padStart(4, "0"), + }), 580, 28, ); @@ -75,18 +80,18 @@ function initializeDinoDemo(demo) { context.textAlign = "center"; context.font = "15px system-ui"; context.fillText( - crashed ? "Hit a cactus. Try another speed." : "Space or Jump ↑", + message(crashed ? "msgCanvasCrashed" : "msgCanvasReady"), 330, 85, ); } }; - const stop = (message) => { + const stop = (notice) => { running = false; cancelAnimationFrame(frame); - start.textContent = crashed ? "Play again" : "Play"; - if (message) status.textContent = message; + start.textContent = message(crashed ? "msgPlayAgain" : "msgPlay"); + if (notice) status.textContent = notice; draw(); }; @@ -99,8 +104,8 @@ function initializeDinoDemo(demo) { obstacles = [{ x: 550, height: 38 }]; if (auto.checked) speed = SPEED_RULE.start; elapsed = 0; - start.textContent = "Play"; - status.textContent = "Press Play, then jump over the cactus."; + start.textContent = message("msgPlay"); + status.textContent = message("msgReady"); updateSpeedDisplay(); draw(); }; @@ -134,7 +139,7 @@ function initializeDinoDemo(demo) { ) ) { crashed = true; - stop("Hit a cactus. Press Play again, or change the speed and restart."); + stop(message("msgCrashed")); } }; @@ -157,8 +162,8 @@ function initializeDinoDemo(demo) { running = true; lastTime = performance.now(); elapsed = 0; - start.textContent = "Pause"; - status.textContent = "Running. Space or Jump clears a cactus."; + start.textContent = message("msgPause"); + status.textContent = message("msgRunning"); frame = requestAnimationFrame(animate); }; @@ -169,7 +174,7 @@ function initializeDinoDemo(demo) { }; start.addEventListener("click", () => { - if (running) stop("Paused. Press Play to continue."); + if (running) stop(message("msgPaused")); else play(); }); demo.querySelector("[data-dino-jump]").addEventListener("click", jump); @@ -188,25 +193,25 @@ function initializeDinoDemo(demo) { auto.checked = false; speed = Number(slider.value); updateSpeedDisplay(); - status.textContent = running - ? `Fixed speed: ${speed.toFixed(1)}. Space or Jump clears a cactus.` - : `Fixed speed: ${speed.toFixed(1)}. Press Play to try it.`; + status.textContent = message( + running ? "msgFixedRunning" : "msgFixedStopped", + { speed: speed.toFixed(1) }, + ); draw(); }); auto.addEventListener("change", () => { if (auto.checked) speed = SPEED_RULE.start; updateSpeedDisplay(); status.textContent = auto.checked - ? "Recovered rule: start at 6, then increase toward 13." - : `Fixed speed: ${speed.toFixed(1)}.`; + ? message("msgRule") + : message("msgFixed", { speed: speed.toFixed(1) }); }); document.addEventListener("visibilitychange", () => { - if (document.hidden && running) stop("Paused. Press Play to continue."); + if (document.hidden && running) stop(message("msgPaused")); }); if ("IntersectionObserver" in window) { new IntersectionObserver((entries) => { - if (!entries[0].isIntersecting && running) - stop("Paused. Press Play to continue."); + if (!entries[0].isIntersecting && running) stop(message("msgPaused")); }).observe(demo); } demo.querySelector(".dino-fallback").setAttribute("hidden", ""); @@ -229,7 +234,8 @@ speedCheck?.addEventListener("click", () => { matches = matches && speed === cell.parentElement.children[1].textContent.trim(); }); - document.querySelector("[data-speed-check-status]").textContent = matches - ? "Replayed the recovered rule. All four values match the controlled original-game check when rounded to three decimals." - : "The replay differs from the recorded original-game values. Compare the speed rule and settings above."; + const status = document.querySelector("[data-speed-check-status]"); + status.textContent = matches + ? status.dataset.msgMatch + : status.dataset.msgMismatch; }); diff --git a/website/public/assets/home.js b/website/public/assets/home.js index c5e102da6..2dfdd1b98 100644 --- a/website/public/assets/home.js +++ b/website/public/assets/home.js @@ -5,6 +5,9 @@ function initializePercentDemo() { const expression = demo.querySelector("[data-percent-expression]"); const status = demo.querySelector("[data-percent-status]"); const equals = demo.querySelector('[data-percent-key="equals"]'); + // The page owns the localized messages; {name} marks an inserted value. + const message = (name, values = {}) => + demo.dataset[name].replace(/\{(\w+)\}/g, (_, key) => values[key]); const operations = demo.querySelectorAll("[data-percent-operation]"); let operation = "add"; let stage = "input"; @@ -24,12 +27,10 @@ function initializePercentDemo() { equals.disabled = stage !== "percent"; status.textContent = stage === "input" - ? "Press % to see what happens to 10." + ? message("msgInput") : stage === "percent" - ? adding - ? "10% of 200 is 20. Press = to add it." - : "For multiplication, 10 becomes 0.1. Press = to multiply." - : `200 ${operator} ${percent} = ${result}.`; + ? message(adding ? "msgPercentAdd" : "msgPercentMultiply") + : message("msgResult", { operator, percent, result }); }; operations.forEach((button) => { diff --git a/website/public/assets/main.js b/website/public/assets/main.js index b927dff64..a4da7c954 100644 --- a/website/public/assets/main.js +++ b/website/public/assets/main.js @@ -1,10 +1,15 @@ function initializeCopyButtons() { + // The shared footer owns the localized copy messages. + const status = document.getElementById("copy-status"); + if (status === null) return; + const messages = status.dataset; + document.querySelectorAll("[data-copy]").forEach((button) => { + const label = button.textContent; button.addEventListener("click", async () => { const target = document.getElementById(button.getAttribute("data-copy")); if (target === null) return; - const status = document.getElementById("copy-status"); const content = target.textContent.trim(); const text = target.closest(".terminal-prompt") === null @@ -12,8 +17,8 @@ function initializeCopyButtons() { : content.replace(/\s+/g, " "); try { await navigator.clipboard.writeText(text); - button.textContent = "Copied"; - if (status !== null) status.textContent = "Code copied to clipboard."; + button.textContent = messages.copied; + status.textContent = messages.statusCopied; } catch { const range = document.createRange(); range.selectNodeContents(target); @@ -22,13 +27,12 @@ function initializeCopyButtons() { selection.removeAllRanges(); selection.addRange(range); } - button.textContent = "Selected"; - if (status !== null) - status.textContent = "Code selected. Use your keyboard to copy it."; + button.textContent = messages.selected; + status.textContent = messages.statusSelected; } window.setTimeout(() => { - button.textContent = "Copy"; + button.textContent = label; }, 2000); }); }); @@ -128,8 +132,15 @@ async function initializeGitHubStars() { const stars = repository.stargazers_count; if (!Number.isSafeInteger(stars) || stars < 0) return; - const formatted = new Intl.NumberFormat("en-US").format(stars); - const label = `REA on GitHub (${formatted} ${stars === 1 ? "star" : "stars"})`; + // The shared header owns one localized label per plural category. + const lang = document.documentElement.lang || undefined; + const category = new Intl.PluralRules(lang).select(stars); + const template = + link.dataset[`label${category[0].toUpperCase()}${category.slice(1)}`] ?? + link.dataset.labelOther; + if (template === undefined) return; + const formatted = new Intl.NumberFormat(lang).format(stars); + const label = template.replace("{count}", formatted); count.textContent = formatted; count.hidden = false; link.setAttribute("aria-label", label); diff --git a/website/public/assets/styles.css b/website/public/assets/styles.css index 5e566f39c..60fdfb6c5 100644 --- a/website/public/assets/styles.css +++ b/website/public/assets/styles.css @@ -6,8 +6,10 @@ --soft: #f4f6f8; --accent: #294f82; --page: #ffffff; - font-family: + --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif; + --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace; + font-family: var(--font-sans); font-synthesis: none; text-rendering: optimizeLegibility; } @@ -44,7 +46,7 @@ button { } code, pre { - font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; + font-family: var(--font-mono); } code { font-size: 0.9em; @@ -57,7 +59,7 @@ kbd { border-radius: 3px; background: var(--soft); color: var(--ink); - font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; + font-family: var(--font-mono); font-size: 0.85em; white-space: nowrap; } @@ -932,7 +934,7 @@ pre code { font-variant-numeric: tabular-nums; } .aegis-calculation .aegis-code { - font-family: ui-monospace, SFMono-Regular, Consolas, monospace; + font-family: ui-monospace, var(--font-mono); font-size: 1.5rem; letter-spacing: 0.06em; } @@ -1264,7 +1266,7 @@ pre code { margin: 0; padding: 1.4rem; color: #f1f4f8; - font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; + font-family: var(--font-mono); font-size: 0.9rem; line-height: 1.9; } @@ -1878,7 +1880,7 @@ pre code { gap: 0.5rem; } .expert-facts dt { - font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; + font-family: var(--font-mono); } .expert-facts dd { margin: 0; @@ -2137,7 +2139,7 @@ pre code { font-size: 0.875rem; } .dino-speed-label output { - font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; + font-family: var(--font-mono); font-variant-numeric: tabular-nums; color: var(--accent); } diff --git a/website/public/blog/index.html b/website/public/blog/index.html index 0f0a5a9d8..b0ad8f862 100644 --- a/website/public/blog/index.html +++ b/website/public/blog/index.html @@ -54,9 +54,10 @@ - + +