diff --git a/CHANGELOG.md b/CHANGELOG.md index 069542a..b86f95d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ 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 (#26, thanks @daniloctdev). - Want the real thing? The title screen, the help page and the victory screen now point to How the Internet Works by Thomas Kjær Aabo, an interactive, zoomable guide to how your packets actually travel. diff --git a/README.md b/README.md index 14ca84e..e817a43 100644 --- a/README.md +++ b/README.md @@ -44,17 +44,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 @@ -63,6 +68,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). Ordinary 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..17754f9 --- /dev/null +++ b/scripts/i18n-check.js @@ -0,0 +1,72 @@ +#!/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.runInContext(s, CTX); + +// English keys used by the game. Calls whose text is not a literal cannot be checked and are skipped. +function sourceKeys(html) { + const keys = new Set(); + const scripts = [...html.matchAll(/