From 04eb32e0a5b356d3c51000bf090641862009d7fb Mon Sep 17 00:00:00 2001 From: Danilo Carbonaro <107484701+daniloctdev@users.noreply.github.com> Date: Sat, 24 Oct 2026 15:06:18 +0200 Subject: [PATCH 1/4] Add Italian translation and a language switch English stays the source text and the default. Player-facing strings go through tr()/trn(), which look the English up in a per-language dictionary (site/i18n/.js) and fall back to it unchanged. The dictionary is only loaded when the game runs in that language. The language follows the browser on the first visit and can be switched under Settings or on the title screen; the choice is remembered. - site/i18n/it.js: complete Italian translation (~1900 entries) - scripts/i18n-check.js / npm run i18n:check: lists missing or stale entries and translations that drop a {placeholder} or HTML tag - tests/i18n.test.js: language selection, fallback, dictionary integrity, and a tour of every screen, failure and event in English and Italian --- CHANGELOG.md | 4 + README.md | 16 + package.json | 3 +- scripts/i18n-check.js | 76 ++ site/i18n/it.js | 1889 ++++++++++++++++++++++++++++++++++++ site/index.html | 2129 +++++++++++++++++++++-------------------- tests/harness.js | 3 + tests/i18n.test.js | 99 ++ 8 files changed, 3165 insertions(+), 1054 deletions(-) create mode 100644 scripts/i18n-check.js create mode 100644 site/i18n/it.js create mode 100644 tests/i18n.test.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d2f476..a490d64 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ All notable changes to this project are documented here. The project follows ## [Unreleased] +- Series of Tubes now speaks Italian. The game follows your browser's + language the first time, and you can switch between English and Italian + under Settings or on the title screen; the choice is remembered. + ## [1.11.0] — 2026-10-24 - Very long dark fiber works now (#17, #30). Optics drop to a slower, longer- diff --git a/README.md b/README.md index fc9c374..7662e61 100644 --- a/README.md +++ b/README.md @@ -34,17 +34,22 @@ open site/index.html # or: npm run serve Progress is saved in your browser's local storage. +The game speaks English and Italian. It follows your browser's language the first time +and remembers the one you pick under Settings or on the title screen. + ## Development ```sh npm ci npm test # headless tests: boot, geography, a year of play, every incident, every panel npm run build # writes the deployable site to _site/ with version and date stamped in +npm run i18n:check # lists text missing from (or stale in) the translations ``` ``` site/ everything that is deployed index.html the whole game (HTML, CSS and JS in one file) + i18n/it.js Italian translation, loaded only when the game runs in Italian images/og-image.png social preview (1200×630) favicon.*, icon-* favicons, app icons, manifest robots.txt, sitemap.xml, llms.txt, 404.html, CNAME @@ -53,6 +58,17 @@ tests/ node:test + jsdom .github/workflows/ ci.yml (pushes to main and PRs) and release.yml (Pages deploy) ``` +## Translations + +English is the source text. Player-facing strings in `index.html` go through +`tr('Unlocks at level {n}.', {n})` (or `trn(one, other, n)` for plurals); static markup +uses `data-i18n`, and `aria-label`/`title` are translated at boot. Each language is a +`site/i18n/.js` file mapping the English text to its translation, plus an entry in +`SOT_LANGS` (the language loader at the top of the page). Missing entries fall back to +English, so new English text never breaks the game; `npm run i18n:check` lists what +needs translating, and the tests make sure every translation keeps its `{placeholders}` +and HTML tags. + ## Releasing Only published releases reach [seriesoftub.es](https://seriesoftub.es). Pushes to diff --git a/package.json b/package.json index 270d242..494cba4 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,9 @@ "homepage": "https://seriesoftub.es/", "repository": { "type": "git", "url": "git+https://github.com/fjaeckel/seriesoftubes.git" }, "scripts": { - "test": "node --test --test-concurrency=1 tests/game.test.js tests/build.test.js tests/persist.test.js tests/services.test.js tests/peering.test.js tests/issues.test.js tests/regions.test.js tests/modes.test.js", + "test": "node --test --test-concurrency=1 tests/game.test.js tests/build.test.js tests/persist.test.js tests/services.test.js tests/peering.test.js tests/issues.test.js tests/regions.test.js tests/modes.test.js tests/i18n.test.js", "build": "bash scripts/build.sh", + "i18n:check": "node scripts/i18n-check.js", "serve": "npm run build && npx --yes serve@14.2.4 _site" }, "engines": { "node": ">=20" }, diff --git a/scripts/i18n-check.js b/scripts/i18n-check.js new file mode 100644 index 0000000..af224c4 --- /dev/null +++ b/scripts/i18n-check.js @@ -0,0 +1,76 @@ +#!/usr/bin/env node +// Checks a translation against the English text in site/index.html: every tr()/trn()/N_() literal and +// every data-i18n text, aria-label and title in the static markup should have an entry, no stale entry +// should linger, and each translation must keep the {placeholders} and HTML tags of its English key. +// Usage: node scripts/i18n-check.js [lang ...] (default: every site/i18n/*.js) +const fs = require('node:fs'); +const path = require('node:path'); +const vm = require('node:vm'); + +const SITE = path.join(__dirname, '..', 'site'); +const LIT = String.raw`'(?:[^'\\\n]|\\.)*'|"(?:[^"\\\n]|\\.)*"|\x60(?:[^\x60\\$]|\\.|\$(?!\{))*\x60`; +const CALL = new RegExp(String.raw`(? vm.runInNewContext(s); + +// English keys used by the game, plus calls whose text is not a literal (those cannot be checked). +function sourceKeys(html) { + const keys = new Set(), dynamic = []; + const scripts = [...html.matchAll(/