Localization: 12 UI languages + exercise instructions in 10 (#7)

Adds a Language setting (Settings → Appearance) that translates the whole
app: a tiny dependency-free i18n layer (English source strings as keys,
per-language dictionaries in frontend/src/locales/) plus per-language
exercise-instruction packs generated from the upstream dataset
(frontend/src/instr/, via scripts/build-instructions.mjs).

UI: en, de, es, fr, it, pt, pl, tr, ru, zh, ko, hi. Instructions: all of
those except de/pt (not in the upstream dataset — fall back to English).
Body-part/equipment/muscle labels and date formats are localized too;
exercise names stay English (upstream limitation).

Everything is lazy-loaded per language (Vite code-splitting), so the
initial bundle is unchanged; the choice syncs with the profile like the
theme. Closes #7.
This commit is contained in:
Duarte Santos committed 2026-07-21 21:45:24 +02:00
1 parent b9f8d18bbd
commit c05b0756ec
44 files changed
+3891 -274

No files matched your search

+41
View File
@@ -0,0 +1,41 @@
#!/usr/bin/env node
// Regenerates the per-language exercise instruction packs in frontend/src/instr/
// from the upstream dataset (hasaneyldrm/exercises-dataset). English stays inline
// in exercises-data.js; every other language ships as its own lazy-loaded pack.
//
// node scripts/build-instructions.mjs [path-to-exercises.json]
//
// Without an argument the dataset is downloaded from the upstream repo.
import { readFileSync, writeFileSync, mkdirSync } from 'node:fs'
import { dirname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
const UPSTREAM = 'https://raw.githubusercontent.com/hasaneyldrm/exercises-dataset/main/data/exercises.json'
const LANGS = ['es', 'fr', 'it', 'tr', 'ru', 'zh', 'hi', 'pl', 'ko']
const root = join(dirname(fileURLToPath(import.meta.url)), '..')
const outDir = join(root, 'frontend', 'src', 'instr')
let raw
if (process.argv[2]) {
raw = readFileSync(process.argv[2], 'utf8')
} else {
console.log('Downloading upstream dataset…')
const res = await fetch(UPSTREAM)
if (!res.ok) throw new Error('Download failed: HTTP ' + res.status)
raw = await res.text()
}
const data = JSON.parse(raw)
mkdirSync(outDir, { recursive: true })
for (const lang of LANGS) {
const pack = {}
for (const ex of data) {
const steps = ex.instruction_steps && ex.instruction_steps[lang]
if (steps && steps.length) pack[ex.id] = steps
}
const file = join(outDir, lang + '.js')
writeFileSync(file, '// generated by scripts/build-instructions.mjs — do not edit\nexport default ' + JSON.stringify(pack) + '\n')
console.log(`${file}: ${Object.keys(pack).length} exercises`)
}