Files
kuentagym/scripts/build-hu-exercise-names.mjs
T
Zoltan K 41df6cb139 i18n: Add Hungarian (hu) — UI, exercise instructions, and exercise names
Rebased onto the Brazilian-Portuguese localization that landed while this was
in progress — that MR introduced EXERCISE_NAME_LANGS/exerciseNameFor()/
exerciseNameSearchText() in lib/i18n-core.js and a generated-pack convention
(scripts/exercise-name-sources/<lang>.json → scripts/build-<lang>-exercise-
names.mjs → frontend/src/exercise-names/<lang>.js), which is exactly the
mechanism this MR originally invented independently as NAME_LANGS/nameFor().
Dropped that duplicate plumbing entirely and reused theirs instead:

- frontend/src/locales/hu.js — full UI translation, 740/740 keys (654 from
  the original translation pass, 86 more added to cover the drop-set/rest-
  pause, equipment-profile, server-pairing and session-note strings that
  landed in the same window).
- frontend/src/instr/hu.js — unchanged mechanism, all 1,324 exercises' step-
  by-step instructions. The upstream exercise dataset (hasaneyldrm/exercises-
  dataset) still has no hu field, so this stays hand-maintained here.
- scripts/exercise-name-sources/hu.json + scripts/build-hu-exercise-
  names.mjs (mirrors the pt-BR ones) → frontend/src/exercise-names/hu.js —
  all 1,324 exercise names, added to EXERCISE_NAME_LANGS. Exercise names
  now render the same bilingual way pt-BR's do: the translated name alone
  when it's the same loanword as English (e.g. "burpee"), otherwise
  "translated (english)".
- One small generalization to exerciseNameFor(): its loanword-casing
  comparison was hardcoded to `.toLocaleLowerCase('pt-BR')`. Changed to the
  active language instead, so it is correct for hu (and any language after
  it) rather than only for pt-BR. No behavior change for pt-BR itself.
- Workout.remove.test.jsx's locale-coverage test hardcoded an expected pack
  count; already fixed once for the 12th language, re-applied here since hu
  is now the 14th — derives the count from LANGS so this stops recurring.

Translated in bulk with AI assistance and validated programmatically (id
coverage against the 1,324-exercise catalogue, key-set parity across all 13
locales via check-locales.mjs, duplicate/collision and encoding checks) —
not yet proofread line-by-line by a fluent human reviewer, same disclosure
standard scripts/exercise-name-sources/README.md and instruction-sources/
README.md already hold the pt-BR translations to.

node frontend/scripts/check-locales.mjs: 13 locales, 740 keys each, in sync.
Full frontend test suite: 39 files / 533 tests passing.
2026-08-29 23:04:10 +02:00

29 lines
1.4 KiB
JavaScript

#!/usr/bin/env node
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs'
import { dirname, join } from 'node:path'
import { fileURLToPath, pathToFileURL } from 'node:url'
const root = join(dirname(fileURLToPath(import.meta.url)), '..')
const sourcePath = join(root, 'scripts', 'exercise-name-sources', 'hu.json')
const outputPath = join(root, 'frontend', 'src', 'exercise-names', 'hu.js')
const exercisesPath = join(root, 'frontend', 'src', 'lib', 'exercises-data.js')
const source = JSON.parse(readFileSync(sourcePath, 'utf8'))
const { EXDB } = await import(pathToFileURL(exercisesPath))
const known = new Set(EXDB.map(exercise => exercise.id))
for (const id of Object.keys(source)) {
if (!known.has(id)) throw new Error(`Unknown exercise ID: ${id}`)
if (typeof source[id] !== 'string' || !source[id].trim()) throw new Error(`${id}: name must be a non-empty string`)
}
if (Object.keys(source).length !== EXDB.length) {
throw new Error(`Incomplete hu exercise names: ${Object.keys(source).length}/${EXDB.length}`)
}
const ordered = {}
for (const exercise of EXDB) ordered[exercise.id] = source[exercise.id].trim()
mkdirSync(dirname(outputPath), { recursive: true })
writeFileSync(outputPath, '// generated by scripts/build-hu-exercise-names.mjs — edit scripts/exercise-name-sources/hu.json\nexport default ' + JSON.stringify(ordered) + '\n')
console.log(`Generated ${EXDB.length}/${EXDB.length} hu exercise names.`)