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(/