Skip to content

Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.

test: exercise-name packs in one test, checked against catalogue/i18n

Duarte Santos646beeab3859
diff --git a/frontend/src/lib/de-exercise-names.test.js b/frontend/src/lib/de-exercise-names.test.js
deleted file mode 100644
index 88e65a580..000000000
--- a/frontend/src/lib/de-exercise-names.test.js
+++ /dev/null
@@ -1,78 +0,0 @@
-import { afterEach, describe, expect, test } from 'vitest'
-import { readFileSync } from 'node:fs'
-import de from '../exercise-names/de.js'
-import { EXDB } from './exercises-data.js'
-import { AWAITING_REVIEW, checkName, stagedExercises } from '../../../scripts/de-name-rules.mjs'
-import {
- EXERCISE_NAME_LANGS, _setLangState, derivePack, exerciseNameFor, exerciseNameSearchText
-} from './i18n-core.js'
-
-// German ships as a stage, not as a complete pack: the catalogue entries done with equipment.
-// That is why this file asserts the staged set rather than EXDB.length the way the pt-BR test
-// does — "incomplete" here is the stated shape, and the test's job is to stop it drifting.
-describe('German exercise names', () => {
- const source = JSON.parse(readFileSync(new URL('../../../scripts/exercise-name-sources/de.json', import.meta.url), 'utf8'))
- const staged = stagedExercises(EXDB)
- afterEach(() => _setLangState('en', {}, null, null))
-
- test('matches the curated source and covers exactly the staged exercises', () => {
- expect(de).toEqual(source)
- expect(Object.keys(de)).toHaveLength(staged.length)
- expect(EXERCISE_NAME_LANGS).toContain('de')
- })
-
- test('covers every staged exercise, and nothing outside the stage', () => {
- for (const exercise of staged) expect(de[exercise.id]?.trim(), exercise.id).toBeTruthy()
- for (const exercise of EXDB) {
- if (exercise.eq && exercise.eq !== 'body weight' && !AWAITING_REVIEW.has(exercise.id)) continue
- const why = AWAITING_REVIEW.has(exercise.id) ? 'awaits native review' : 'is body weight'
- expect(de[exercise.id], `${exercise.id} ${why} and must stay English`).toBeUndefined()
- }
- })
-
- // The same rules the translator corrects batches against, as a build failure. Both read
- // scripts/de-name-rules.mjs, so a rule relaxed for the translator is relaxed here too — which
- // is the point: there is one definition of what a German name may look like.
- test('every name obeys the naming rules', () => {
- const broken = []
- for (const exercise of staged) {
- const violations = checkName(exercise, de[exercise.id])
- if (violations.length) broken.push(`${exercise.id} "${de[exercise.id]}": ${violations.map(v => v.rule).join(', ')}`)
- }
- expect(broken).toEqual([])
- })
-
- test('shows German first and preserves the canonical English title', () => {
- const exercise = staged[0]
- _setLangState('de', {}, null, de)
- expect(exerciseNameFor(exercise)).toBe(`${de[exercise.id]} (${exercise.n})`)
- expect(exerciseNameSearchText(exercise)).toContain(de[exercise.id])
- expect(exerciseNameSearchText(exercise)).toContain(exercise.n)
- })
-
- test('falls back to the English title for a body-weight exercise', () => {
- const bodyWeight = EXDB.find(exercise => exercise.eq === 'body weight')
- _setLangState('de', {}, null, de)
- expect(exerciseNameFor(bodyWeight)).toBe(bodyWeight.n)
- })
-
- // de-CH derives from this pack by replacing ß with ss, so the base pack must be the ß one or
- // the Swiss locale derives nothing. A name written with ss here would pass every other test.
- test('de-CH derives the Swiss spelling from this pack', () => {
- const withSharpS = Object.entries(de).filter(([, name]) => name.includes('ß'))
- expect(withSharpS.length).toBeGreaterThan(0)
- const swiss = derivePack('de-CH', de)
- for (const [id, name] of withSharpS) {
- expect(swiss[id], id).toBe(name.replaceAll('ß', 'ss'))
- expect(swiss[id], id).not.toContain('ß')
- }
- })
-
- test('never translates custom exercises or changes other languages', () => {
- const custom = { id: 'custom-1', n: 'Meine Übung' }
- _setLangState('de', {}, null, de)
- expect(exerciseNameFor(custom)).toBe('Meine Übung')
- _setLangState('en', {}, null, null)
- expect(exerciseNameFor(staged[0])).toBe(staged[0].n)
- })
-})
diff --git a/frontend/src/lib/es-exercise-names.test.js b/frontend/src/lib/es-exercise-names.test.js
deleted file mode 100644
index caa015205..000000000
--- a/frontend/src/lib/es-exercise-names.test.js
+++ /dev/null
@@ -1,62 +0,0 @@
-import { afterEach, describe, expect, test } from 'vitest'
-import { readFileSync } from 'node:fs'
-import es from '../exercise-names/es.js'
-import { EXDB } from './exercises-data.js'
-import {
- EXERCISE_NAME_LANGS, _setLangState, exerciseNameFor, exerciseNameSearchText
-} from './i18n-core.js'
-
-describe('Spanish exercise names', () => {
- const source = JSON.parse(readFileSync(new URL('../../../scripts/exercise-name-sources/es.json', import.meta.url), 'utf8'))
- afterEach(() => _setLangState('en', {}, null, null))
-
- test('matches the curated source and covers the complete built-in catalogue', () => {
- expect(Object.keys(es)).toHaveLength(EXDB.length)
- expect(es).toEqual(source)
- expect(EXERCISE_NAME_LANGS).toContain('es')
- })
-
- test('contains a non-empty translation for every known exercise', () => {
- for (const exercise of EXDB) {
- expect(es[exercise.id]?.trim(), exercise.id).toBeTruthy()
- }
- })
-
- test('preserves identity-changing qualifiers and equipment', () => {
- const rules = [
- [/assisted/iu, /asistid/iu],
- [/weighted/iu, /(?:peso|lastre)/iu],
- [/(?:^|[^\p{L}])male(?=$|[^\p{L}])/iu, /masculin/iu],
- [/(?:^|[^\p{L}])female(?=$|[^\p{L}])/iu, /femenin/iu],
- [/barbell/iu, /barra/iu],
- [/dumbbell/iu, /mancuerna/iu],
- [/kettlebell/iu, /kettlebell/iu],
- [/smith/iu, /smith/iu],
- [/stability ball/iu, /balón de estabilidad/iu],
- [/medicine ball/iu, /balón medicinal/iu],
- [/\bbands?\b/iu, /banda/iu],
- [/\bcables?\b/iu, /polea/iu],
- ]
- for (const exercise of EXDB) {
- for (const [english, spanish] of rules) {
- if (english.test(exercise.n)) expect(es[exercise.id], `${exercise.id}: ${english}`).toMatch(spanish)
- }
- }
- })
-
- test('shows Spanish first and preserves the canonical English title', () => {
- const exercise = EXDB[0]
- _setLangState('es', {}, null, es)
- expect(exerciseNameFor(exercise)).toBe(`${es[exercise.id]} (${exercise.n})`)
- expect(exerciseNameSearchText(exercise)).toContain(es[exercise.id])
- expect(exerciseNameSearchText(exercise)).toContain(exercise.n)
- })
-
- test('never translates custom exercises or changes other languages', () => {
- const custom = { id: 'custom-1', n: 'Mi ejercicio' }
- _setLangState('es', {}, null, es)
- expect(exerciseNameFor(custom)).toBe('Mi ejercicio')
- _setLangState('en', {}, null, null)
- expect(exerciseNameFor(EXDB[0])).toBe(EXDB[0].n)
- })
-})
diff --git a/frontend/src/lib/exercise-names.test.js b/frontend/src/lib/exercise-names.test.js
new file mode 100644
index 000000000..8fb7aefd6
--- /dev/null
+++ b/frontend/src/lib/exercise-names.test.js
@@ -0,0 +1,283 @@
+import { afterEach, describe, expect, test } from 'vitest'
+import { readFileSync } from 'node:fs'
+import { EXDB } from './exercises-data.js'
+import V13_IDS from './catalogue-v13-ids.json' with { type: 'json' }
+import { checkName, stagedExercises } from '../../../scripts/de-name-rules.mjs'
+import {
+ EXERCISE_NAME_LANGS, _setLangState, derivePack, exerciseNameFor, exerciseNameSearchText
+} from './i18n-core.js'
+
+// Every translated-name pack, checked the same way. The packs are generated from
+// catalogue/i18n/<lang>.json and may be partial (anything missing shows the English title), so
+// coverage and the language rules below are pinned on the 1,324 entries of the v1.3 catalogue,
+// whose names were curated and reviewed. Names for the v1.4 additions only have to be well formed.
+const packs = import.meta.glob('../exercise-names/*.js', { eager: true, import: 'default' })
+const EXIDX = new Map(EXDB.map(exercise => [exercise.id, exercise]))
+const LEGACY_IDS = new Set(V13_IDS)
+const legacy = EXDB.filter(exercise => LEGACY_IDS.has(exercise.id))
+const catalogueNames = lang => {
+ const rows = JSON.parse(readFileSync(new URL(`../../../catalogue/i18n/${lang}.json`, import.meta.url), 'utf8'))
+ return Object.fromEntries(Object.entries(rows).filter(([, row]) => row.name).map(([id, row]) => [id, row.name]))
+}
+
+const MALE = /(?:^|[^\p{L}])male(?=$|[^\p{L}])/iu
+const FEMALE = /(?:^|[^\p{L}])female(?=$|[^\p{L}])/iu
+
+// What the v1.3 names were held to, per language.
+// covers: the v1.3 entries the pack translates in full
+// keep: [English, translated] — a qualifier or piece of equipment in the English title that
+// has to survive translation, since it changes which exercise it is
+// forbid: words a name must not contain (English left untranslated, rejected calques)
+// require: a pattern every name has to match
+// distinct: no two different v1.3 exercises share a name
+// loanword: "burpee" is the local term too, so it shows without the English repeated
+const LANGS = {
+ // German ships as a stage: the equipment entries, without the body-weight ones and the ones
+ // awaiting native review. The naming rules live in scripts/de-name-rules.mjs, shared with
+ // the translator so a rule cannot drift between the two.
+ de: { covers: stagedExercises(legacy), check: checkName },
+ es: {
+ covers: legacy,
+ keep: [
+ [/assisted/iu, /asistid/iu],
+ [/weighted/iu, /(?:peso|lastre)/iu],
+ [MALE, /masculin/iu],
+ [FEMALE, /femenin/iu],
+ [/barbell/iu, /barra/iu],
+ [/dumbbell/iu, /mancuerna/iu],
+ [/kettlebell/iu, /kettlebell/iu],
+ [/smith/iu, /smith/iu],
+ [/stability ball/iu, /balón de estabilidad/iu],
+ [/medicine ball/iu, /balón medicinal/iu],
+ [/\bbands?\b/iu, /banda/iu],
+ [/\bcables?\b/iu, /polea/iu],
+ ],
+ },
+ fr: {
+ covers: legacy,
+ loanword: true,
+ forbid: /(?:^|[^\p{L}])(?:barbell|dumbbell|cable|stability ball|medicine ball|assisted|weighted)(?=$|[^\p{L}])/iu,
+ keep: [
+ [/assisted/iu, /assisté/iu],
+ [/weighted/iu, /lesté/iu],
+ [MALE, /masculin/iu],
+ [FEMALE, /féminin/iu],
+ [/barbell/iu, /barre/iu],
+ [/dumbbell/iu, /haltère/iu],
+ [/kettlebell/iu, /kettlebell/iu],
+ [/smith/iu, /multipower/iu],
+ [/stability ball/iu, /ballon de stabilité/iu],
+ [/exercise ball/iu, /ballon de stabilité/iu],
+ [/medicine ball/iu, /médecine-ball/iu],
+ [/cable/iu, /câble/iu],
+ [/band/iu, /élastique/iu],
+ ],
+ },
+ hu: { covers: legacy, distinct: true },
+ it: {
+ covers: legacy,
+ loanword: true,
+ forbid: /(?:^|[^\p{L}])(?:barbell|dumbbell|cable|stability ball|medicine ball|assisted|weighted)(?=$|[^\p{L}])/iu,
+ keep: [
+ [/assisted/iu, /assistit/iu],
+ [/weighted/iu, /con peso/iu],
+ [MALE, /maschil/iu],
+ [FEMALE, /femminil/iu],
+ [/barbell/iu, /bilancier/iu],
+ [/dumbbell/iu, /manubri/iu],
+ [/kettlebell/iu, /kettlebell/iu],
+ [/smith/iu, /multipower/iu],
+ [/stability ball/iu, /fitball/iu],
+ [/exercise ball/iu, /fitball/iu],
+ [/medicine ball/iu, /palla medica/iu],
+ [/band/iu, /fascia elastica/iu],
+ ],
+ },
+ pl: {
+ covers: legacy,
+ loanword: true,
+ distinct: true,
+ forbid: /(?:^|[^\p{L}])(?:barbell|dumbbell|cable|band|stability ball|exercise ball|medicine ball|assisted|weighted)(?=$|[^\p{L}])/iu,
+ keep: [
+ [/assisted/iu, /asyst|wspomag/iu],
+ [/weighted/iu, /obciąż/iu],
+ [MALE, /mężczyzn/iu],
+ [FEMALE, /kobiet/iu],
+ [/barbell/iu, /sztang/iu],
+ [/dumbbell/iu, /hantl/iu],
+ [/kettlebell/iu, /kettlebell/iu],
+ [/smith/iu, /smitha/iu],
+ [/stability ball/iu, /pił[kc]\p{L}* gimnastyczn/iu],
+ [/exercise ball/iu, /pił[kc]\p{L}* gimnastyczn/iu],
+ [/medicine ball/iu, /pił[kc]\p{L}* lekarsk/iu],
+ [/band/iu, /gum/iu],
+ [/ez[- ]bar/iu, /łaman/iu],
+ [/bosu/iu, /bosu/iu],
+ [/trap bar/iu, /trap bar/iu],
+ ],
+ },
+ 'pt-BR': {
+ covers: legacy,
+ // European Portuguese where Brazil says it differently.
+ forbid: /(?:^|[^\p{L}])(?:abdómen|anca|gémeos|ecrã|ginásio|banda|piso|omoplata|pegada inversa|pegada invertida)(?=$|[^\p{L}])/iu,
+ keep: [
+ [/assisted/iu, /assistid/iu],
+ [/weighted/iu, /(?:peso|carga|lastro|ponderad)/iu],
+ [MALE, /masculin/iu],
+ [FEMALE, /feminin/iu],
+ [/barbell/iu, /barra/iu],
+ [/dumbbell/iu, /halter/iu],
+ [/kettlebell/iu, /kettlebell/iu],
+ [/smith/iu, /smith/iu],
+ [/stability ball/iu, /bola de estabilidade/iu],
+ [/medicine ball/iu, /bola medicinal/iu],
+ ],
+ },
+ ru: {
+ covers: legacy,
+ // Cyrillic somewhere in the title: a name left in English would otherwise pass every other
+ // check while showing "barbell bench press (barbell bench press)".
+ require: /\p{Script=Cyrillic}/u,
+ // Transliterated calques the glossary rejects in favour of the term gyms actually use.
+ forbid: /(?:^|[^\p{L}])(?:керл|завиток|череполом|хруст|сит-ап|пуш-ап|пул-ап|чин-ап|кеттлбелл|ассистированн\p{L}*|проповедник|мёртвая тяга)(?=$|[^\p{L}])/iu,
+ keep: [
+ // "ez bar"/"ez barbell" is the EZ bar, and an olympic barbell is named for the bar too,
+ // so a plain "barbell" is the only one that has to say штанга.
+ [/ez[\s-]bar/iu, /ez-гриф/iu],
+ [/(?<!ez[\s-])(?<!olympic )barbell/iu, /штанг/iu],
+ [/olympic barbell/iu, /(?:олимпийск|штанг)/iu],
+ [/dumbbell/iu, /гантел/iu],
+ [/kettlebell/iu, /гир/iu],
+ [/smith/iu, /смит/iu],
+ [/trap bar/iu, /трэп-гриф/iu],
+ [/stability ball/iu, /фитбол/iu],
+ [/medicine ball/iu, /медбол/iu],
+ [/assisted/iu, /(?:поддержк|самопомощ)/iu],
+ [/weighted/iu, /отягощен/iu],
+ [MALE, /муж/iu],
+ [FEMALE, /жен/iu],
+ ],
+ },
+}
+
+test('every curated language still ships a name pack, and every pack is enabled', () => {
+ for (const lang of Object.keys(LANGS)) expect(EXERCISE_NAME_LANGS, lang).toContain(lang)
+ for (const path of Object.keys(packs)) {
+ const lang = path.match(/([^/]+)\.js$/)[1]
+ expect(EXERCISE_NAME_LANGS, path).toContain(lang)
+ }
+})
+
+for (const lang of EXERCISE_NAME_LANGS) {
+ describe(`${lang} exercise names`, () => {
+ const pack = packs[`../exercise-names/${lang}.js`]
+ const rules = LANGS[lang] || {}
+ // The rules hold the curated names: the v1.3 ones, for German only the reviewed stage.
+ const v13 = (rules.covers || legacy).filter(exercise => pack[exercise.id])
+ afterEach(() => _setLangState('en', {}, null, null))
+
+ test('is built from catalogue/i18n, for known exercises only, with non-empty names', () => {
+ expect(pack).toEqual(catalogueNames(lang))
+ for (const [id, name] of Object.entries(pack)) {
+ expect(EXIDX.has(id), `unknown exercise ${id}`).toBe(true)
+ expect(typeof name === 'string' && name.trim(), id).toBeTruthy()
+ expect(name, id).toBe(name.trim())
+ }
+ })
+
+ if (rules.covers) {
+ test('covers the v1.3 catalogue', () => {
+ expect(rules.covers.length).toBeGreaterThan(0)
+ for (const exercise of rules.covers) expect(pack[exercise.id]?.trim(), exercise.id).toBeTruthy()
+ })
+ }
+
+ if (rules.forbid || rules.require) {
+ test('leaves nothing untranslated in the v1.3 names', () => {
+ for (const exercise of v13) {
+ if (rules.forbid) expect(pack[exercise.id], exercise.id).not.toMatch(rules.forbid)
+ if (rules.require) expect(pack[exercise.id], exercise.id).toMatch(rules.require)
+ }
+ })
+ }
+
+ if (rules.keep) {
+ test('preserves identity-changing qualifiers and equipment in the v1.3 names', () => {
+ for (const exercise of v13) {
+ for (const [english, translated] of rules.keep) {
+ if (english.test(exercise.n)) expect(pack[exercise.id], `${exercise.id}: ${exercise.n}`).toMatch(translated)
+ }
+ }
+ })
+ }
+
+ if (rules.check) {
+ test('every v1.3 name obeys the naming rules', () => {
+ const broken = []
+ for (const exercise of v13) {
+ const violations = rules.check(exercise, pack[exercise.id])
+ if (violations.length) broken.push(`${exercise.id} "${pack[exercise.id]}": ${violations.map(v => v.rule).join(', ')}`)
+ }
+ expect(broken).toEqual([])
+ })
+ }
+
+ if (rules.distinct) {
+ test('gives different v1.3 exercises different names', () => {
+ const seen = new Map()
+ for (const exercise of v13) {
+ const name = pack[exercise.id]
+ const other = seen.get(name)
+ if (other) expect(other.n, `${name}: ${other.id} vs ${exercise.id}`).toBe(exercise.n)
+ else seen.set(name, exercise)
+ }
+ })
+ }
+
+ test('shows the translation first with the English title in parentheses, and can hide or replace it', () => {
+ // One whose name differs from the English, or the loanword rule below takes over.
+ const exercise = EXDB.find(e => pack[e.id] && pack[e.id].toLocaleLowerCase(lang) !== e.n.toLocaleLowerCase('en'))
+ const name = pack[exercise.id]
+ _setLangState(lang, {}, null, pack)
+ expect(exerciseNameFor(exercise)).toBe(`${name} (${exercise.n})`)
+ expect(exerciseNameSearchText(exercise)).toContain(name)
+ expect(exerciseNameSearchText(exercise)).toContain(exercise.n)
+ _setLangState(lang, {}, null, pack, false)
+ expect(exerciseNameFor(exercise)).toBe(name)
+ _setLangState(lang, {}, null, pack, true, true)
+ expect(exerciseNameFor(exercise)).toBe(exercise.n)
+ })
+
+ test('falls back to the English title, never translates custom exercises or changes other languages', () => {
+ const exercise = EXDB.find(e => pack[e.id])
+ const { [exercise.id]: _, ...without } = pack
+ _setLangState(lang, {}, null, without)
+ expect(exerciseNameFor(exercise)).toBe(exercise.n)
+ const custom = { id: 'custom-1', n: 'My own exercise' }
+ _setLangState(lang, {}, null, pack)
+ expect(exerciseNameFor(custom)).toBe('My own exercise')
+ _setLangState('en', {}, null, null)
+ expect(exerciseNameFor(exercise)).toBe(exercise.n)
+ })
+
+ if (rules.loanword) {
+ test('keeps loanword names without duplicating the English title', () => {
+ _setLangState(lang, {}, null, pack)
+ expect(exerciseNameFor(EXIDX.get('1160'))).toBe('burpee')
+ })
+ }
+ })
+}
+
+// de-CH derives from the German pack by replacing ß with ss, so the base pack must be the ß one
+// or the Swiss locale derives nothing. A name written with ss there would pass every other test.
+test('de-CH derives the Swiss spelling from the German pack', () => {
+ const de = packs['../exercise-names/de.js']
+ const withSharpS = Object.entries(de).filter(([, name]) => name.includes('ß'))
+ expect(withSharpS.length).toBeGreaterThan(0)
+ const swiss = derivePack('de-CH', de)
+ for (const [id, name] of withSharpS) {
+ expect(swiss[id], id).toBe(name.replaceAll('ß', 'ss'))
+ expect(swiss[id], id).not.toContain('ß')
+ }
+})
diff --git a/frontend/src/lib/fr-exercise-names.test.js b/frontend/src/lib/fr-exercise-names.test.js
deleted file mode 100644
index 436e3086e..000000000
--- a/frontend/src/lib/fr-exercise-names.test.js
+++ /dev/null
@@ -1,74 +0,0 @@
-import { afterEach, describe, expect, test } from 'vitest'
-import { readFileSync } from 'node:fs'
-import frNames from '../exercise-names/fr.js'
-import { EXDB } from './exercises-data.js'
-import {
- EXERCISE_NAME_LANGS, _setLangState, exerciseNameFor, exerciseNameSearchText
-} from './i18n-core.js'
-
-describe('French exercise names', () => {
- const source = JSON.parse(readFileSync(new URL('../../../scripts/exercise-name-sources/fr.json', import.meta.url), 'utf8'))
- afterEach(() => _setLangState('en', {}, null, null))
-
- test('matches the curated source and covers the complete built-in catalogue', () => {
- expect(Object.keys(frNames)).toHaveLength(EXDB.length)
- expect(frNames).toEqual(source)
- expect(EXERCISE_NAME_LANGS).toContain('fr')
- })
-
- test('contains a non-empty translation for every known exercise with no untranslated qualifiers', () => {
- for (const exercise of EXDB) {
- expect(frNames[exercise.id]?.trim(), exercise.id).toBeTruthy()
- expect(frNames[exercise.id], exercise.id).not.toMatch(
- /(?:^|[^\p{L}])(?:barbell|dumbbell|cable|stability ball|medicine ball|assisted|weighted)(?=$|[^\p{L}])/iu
- )
- }
- })
-
- test('preserves identity-changing qualifiers and equipment', () => {
- const rules = [
- [/assisted/iu, /assisté/iu],
- [/weighted/iu, /lesté/iu],
- [/(?:^|[^\p{L}])male(?=$|[^\p{L}])/iu, /masculin/iu],
- [/(?:^|[^\p{L}])female(?=$|[^\p{L}])/iu, /féminin/iu],
- [/barbell/iu, /barre/iu],
- [/dumbbell/iu, /haltère/iu],
- [/kettlebell/iu, /kettlebell/iu],
- [/smith/iu, /multipower/iu],
- [/stability ball/iu, /ballon de stabilité/iu],
- [/exercise ball/iu, /ballon de stabilité/iu],
- [/medicine ball/iu, /médecine-ball/iu],
- [/cable/iu, /câble/iu],
- [/band/iu, /élastique/iu],
- ]
- for (const exercise of EXDB) {
- for (const [english, french] of rules) {
- if (english.test(exercise.n)) expect(frNames[exercise.id], `${exercise.id}: ${english}`).toMatch(french)
- }
- }
- })
-
- test('shows French first, keeps English in parentheses by default, and can hide it', () => {
- const exercise = EXDB[0]
- _setLangState('fr', {}, null, frNames)
- expect(exerciseNameFor(exercise)).toBe(`${frNames[exercise.id]} (${exercise.n})`)
- expect(exerciseNameSearchText(exercise)).toContain(frNames[exercise.id])
- expect(exerciseNameSearchText(exercise)).toContain(exercise.n)
- _setLangState('fr', {}, null, frNames, false)
- expect(exerciseNameFor(exercise)).toBe(frNames[exercise.id])
- })
-
- test('never translates custom exercises or changes other languages', () => {
- const custom = { id: 'custom-1', n: 'Mon exercice' }
- _setLangState('fr', {}, null, frNames)
- expect(exerciseNameFor(custom)).toBe('Mon exercice')
- _setLangState('en', {}, null, null)
- expect(exerciseNameFor(EXDB[0])).toBe(EXDB[0].n)
- })
-
- test('keeps loanword names without duplicating the English title', () => {
- const burpee = EXDB.find(e => e.id === '1160')
- _setLangState('fr', {}, null, frNames)
- expect(exerciseNameFor(burpee)).toBe('burpee')
- })
-})
\ No newline at end of file
diff --git a/frontend/src/lib/it-exercise-names.test.js b/frontend/src/lib/it-exercise-names.test.js
deleted file mode 100644
index b1b6c5e09..000000000
--- a/frontend/src/lib/it-exercise-names.test.js
+++ /dev/null
@@ -1,83 +0,0 @@
-import { afterEach, describe, expect, test } from 'vitest'
-import { readFileSync } from 'node:fs'
-import itNames from '../exercise-names/it.js'
-import { EXDB } from './exercises-data.js'
-import {
- EXERCISE_NAME_LANGS, _setLangState, exerciseNameFor, exerciseNameSearchText
-} from './i18n-core.js'
-
-describe('Italian exercise names', () => {
- const source = JSON.parse(readFileSync(new URL('../../../scripts/exercise-name-sources/it.json', import.meta.url), 'utf8'))
- afterEach(() => _setLangState('en', {}, null, null))
-
- test('matches the curated source and covers the complete built-in catalogue', () => {
- expect(Object.keys(itNames)).toHaveLength(EXDB.length)
- expect(itNames).toEqual(source)
- expect(EXERCISE_NAME_LANGS).toContain('it')
- })
-
- test('contains a non-empty translation for every known exercise with no untranslated qualifiers', () => {
- for (const exercise of EXDB) {
- expect(itNames[exercise.id]?.trim(), exercise.id).toBeTruthy()
- expect(itNames[exercise.id], exercise.id).not.toMatch(
- /(?:^|[^\p{L}])(?:barbell|dumbbell|cable|stability ball|medicine ball|assisted|weighted)(?=$|[^\p{L}])/iu
- )
- }
- })
-
- test('preserves identity-changing qualifiers and equipment', () => {
- const rules = [
- [/assisted/iu, /assistit/iu],
- [/weighted/iu, /con peso/iu],
- [/(?:^|[^\p{L}])male(?=$|[^\p{L}])/iu, /maschil/iu],
- [/(?:^|[^\p{L}])female(?=$|[^\p{L}])/iu, /femminil/iu],
- [/barbell/iu, /bilancier/iu],
- [/dumbbell/iu, /manubri/iu],
- [/kettlebell/iu, /kettlebell/iu],
- [/smith/iu, /multipower/iu],
- [/stability ball/iu, /fitball/iu],
- [/exercise ball/iu, /fitball/iu],
- [/medicine ball/iu, /palla medica/iu],
- [/band/iu, /fascia elastica/iu],
- ]
- for (const exercise of EXDB) {
- for (const [english, italian] of rules) {
- if (english.test(exercise.n)) expect(itNames[exercise.id], `${exercise.id}: ${english}`).toMatch(italian)
- }
- }
- })
-
- test('shows Italian first and preserves the canonical English title', () => {
- const exercise = EXDB[0]
- _setLangState('it', {}, null, itNames)
- expect(exerciseNameFor(exercise)).toBe(`${itNames[exercise.id]} (${exercise.n})`)
- expect(exerciseNameSearchText(exercise)).toContain(itNames[exercise.id])
- expect(exerciseNameSearchText(exercise)).toContain(exercise.n)
- })
-
- test('never translates custom exercises or changes other languages', () => {
- const custom = { id: 'custom-1', n: 'Il mio esercizio' }
- _setLangState('it', {}, null, itNames)
- expect(exerciseNameFor(custom)).toBe('Il mio esercizio')
- _setLangState('en', {}, null, null)
- expect(exerciseNameFor(EXDB[0])).toBe(EXDB[0].n)
- })
-
- test('keeps loanword names without duplicating the English title', () => {
- const burpee = EXDB.find(e => e.id === '1160')
- _setLangState('it', {}, null, itNames)
- expect(exerciseNameFor(burpee)).toBe('burpee')
- })
-
- test('can hide the English name in parentheses per language', () => {
- const exercise = EXDB[0]
- _setLangState('it', {}, null, itNames, false)
- expect(exerciseNameFor(exercise)).toBe(itNames[exercise.id])
- })
-
- test('can replace the translation with the English name only, per language', () => {
- const exercise = EXDB[0]
- _setLangState('it', {}, null, itNames, true, true)
- expect(exerciseNameFor(exercise)).toBe(exercise.n)
- })
-})
diff --git a/frontend/src/lib/pl-exercise-names.test.js b/frontend/src/lib/pl-exercise-names.test.js
deleted file mode 100644
index fd5f1a0cd..000000000
--- a/frontend/src/lib/pl-exercise-names.test.js
+++ /dev/null
@@ -1,96 +0,0 @@
-import { afterEach, describe, expect, test } from 'vitest'
-import { readFileSync } from 'node:fs'
-import plNames from '../exercise-names/pl.js'
-import { EXDB } from './exercises-data.js'
-import {
- EXERCISE_NAME_LANGS, _setLangState, exerciseNameFor, exerciseNameSearchText
-} from './i18n-core.js'
-
-describe('Polish exercise names', () => {
- const source = JSON.parse(readFileSync(new URL('../../../scripts/exercise-name-sources/pl.json', import.meta.url), 'utf8'))
- afterEach(() => _setLangState('en', {}, null, null))
-
- test('matches the curated source and covers the complete built-in catalogue', () => {
- expect(Object.keys(plNames)).toHaveLength(EXDB.length)
- expect(plNames).toEqual(source)
- expect(EXERCISE_NAME_LANGS).toContain('pl')
- })
-
- test('contains a non-empty translation for every known exercise with no untranslated qualifiers', () => {
- for (const exercise of EXDB) {
- expect(plNames[exercise.id]?.trim(), exercise.id).toBeTruthy()
- expect(plNames[exercise.id], exercise.id).not.toMatch(
- /(?:^|[^\p{L}])(?:barbell|dumbbell|cable|band|stability ball|exercise ball|medicine ball|assisted|weighted)(?=$|[^\p{L}])/iu
- )
- }
- })
-
- test('preserves identity-changing qualifiers and equipment', () => {
- const rules = [
- [/assisted/iu, /asyst|wspomag/iu],
- [/weighted/iu, /obciąż/iu],
- [/(?:^|[^\p{L}])male(?=$|[^\p{L}])/iu, /mężczyzn/iu],
- [/(?:^|[^\p{L}])female(?=$|[^\p{L}])/iu, /kobiet/iu],
- [/barbell/iu, /sztang/iu],
- [/dumbbell/iu, /hantl/iu],
- [/kettlebell/iu, /kettlebell/iu],
- [/smith/iu, /smitha/iu],
- [/stability ball/iu, /pił[kc]\p{L}* gimnastyczn/iu],
- [/exercise ball/iu, /pił[kc]\p{L}* gimnastyczn/iu],
- [/medicine ball/iu, /pił[kc]\p{L}* lekarsk/iu],
- [/band/iu, /gum/iu],
- [/ez[- ]bar/iu, /łaman/iu],
- [/bosu/iu, /bosu/iu],
- [/trap bar/iu, /trap bar/iu],
- ]
- for (const exercise of EXDB) {
- for (const [english, polish] of rules) {
- if (english.test(exercise.n)) expect(plNames[exercise.id], `${exercise.id}: ${english}`).toMatch(polish)
- }
- }
- })
-
- test('gives different exercises different names', () => {
- const seen = new Map()
- for (const exercise of EXDB) {
- const name = plNames[exercise.id]
- const other = seen.get(name)
- if (other) expect(other.n, `${name}: ${other.id} vs ${exercise.id}`).toBe(exercise.n)
- else seen.set(name, exercise)
- }
- })
-
- test('shows Polish first and preserves the canonical English title', () => {
- const exercise = EXDB[0]
- _setLangState('pl', {}, null, plNames)
- expect(exerciseNameFor(exercise)).toBe(`${plNames[exercise.id]} (${exercise.n})`)
- expect(exerciseNameSearchText(exercise)).toContain(plNames[exercise.id])
- expect(exerciseNameSearchText(exercise)).toContain(exercise.n)
- })
-
- test('never translates custom exercises or changes other languages', () => {
- const custom = { id: 'custom-1', n: 'Moje ćwiczenie' }
- _setLangState('pl', {}, null, plNames)
- expect(exerciseNameFor(custom)).toBe('Moje ćwiczenie')
- _setLangState('en', {}, null, null)
- expect(exerciseNameFor(EXDB[0])).toBe(EXDB[0].n)
- })
-
- test('keeps loanword names without duplicating the English title', () => {
- const burpee = EXDB.find(e => e.id === '1160')
- _setLangState('pl', {}, null, plNames)
- expect(exerciseNameFor(burpee)).toBe('burpee')
- })
-
- test('can hide the English name in parentheses per language', () => {
- const exercise = EXDB[0]
- _setLangState('pl', {}, null, plNames, false)
- expect(exerciseNameFor(exercise)).toBe(plNames[exercise.id])
- })
-
- test('can replace the translation with the English name only, per language', () => {
- const exercise = EXDB[0]
- _setLangState('pl', {}, null, plNames, true, true)
- expect(exerciseNameFor(exercise)).toBe(exercise.n)
- })
-})
diff --git a/frontend/src/lib/pt-br-exercise-names.test.js b/frontend/src/lib/pt-br-exercise-names.test.js
deleted file mode 100644
index 00ec6d7df..000000000
--- a/frontend/src/lib/pt-br-exercise-names.test.js
+++ /dev/null
@@ -1,61 +0,0 @@
-import { afterEach, describe, expect, test } from 'vitest'
-import { readFileSync } from 'node:fs'
-import ptBR from '../exercise-names/pt-BR.js'
-import { EXDB } from './exercises-data.js'
-import {
- EXERCISE_NAME_LANGS, _setLangState, exerciseNameFor, exerciseNameSearchText
-} from './i18n-core.js'
-
-describe('Brazilian Portuguese exercise names', () => {
- const source = JSON.parse(readFileSync(new URL('../../../scripts/exercise-name-sources/pt-BR.json', import.meta.url), 'utf8'))
- afterEach(() => _setLangState('en', {}, null, null))
-
- test('matches the curated source and covers the complete built-in catalogue', () => {
- expect(Object.keys(ptBR)).toHaveLength(EXDB.length)
- expect(ptBR).toEqual(source)
- expect(EXERCISE_NAME_LANGS).toContain('pt-BR')
- })
-
- test('contains a non-empty translation for every known exercise', () => {
- for (const exercise of EXDB) {
- expect(ptBR[exercise.id]?.trim(), exercise.id).toBeTruthy()
- expect(ptBR[exercise.id], exercise.id).not.toMatch(/(?:^|[^\p{L}])(?:abdómen|anca|gémeos|ecrã|ginásio|banda|piso|omoplata|pegada inversa|pegada invertida)(?=$|[^\p{L}])/iu)
- }
- })
-
- test('preserves identity-changing qualifiers and equipment', () => {
- const rules = [
- [/assisted/iu, /assistid/iu],
- [/weighted/iu, /(?:peso|carga|lastro|ponderad)/iu],
- [/(?:^|[^\p{L}])male(?=$|[^\p{L}])/iu, /masculin/iu],
- [/(?:^|[^\p{L}])female(?=$|[^\p{L}])/iu, /feminin/iu],
- [/barbell/iu, /barra/iu],
- [/dumbbell/iu, /halter/iu],
- [/kettlebell/iu, /kettlebell/iu],
- [/smith/iu, /smith/iu],
- [/stability ball/iu, /bola de estabilidade/iu],
- [/medicine ball/iu, /bola medicinal/iu],
- ]
- for (const exercise of EXDB) {
- for (const [english, portuguese] of rules) {
- if (english.test(exercise.n)) expect(ptBR[exercise.id], `${exercise.id}: ${english}`).toMatch(portuguese)
- }
- }
- })
-
- test('shows Portuguese first and preserves the canonical English title', () => {
- const exercise = EXDB[0]
- _setLangState('pt-BR', {}, null, ptBR)
- expect(exerciseNameFor(exercise)).toBe(`${ptBR[exercise.id]} (${exercise.n})`)
- expect(exerciseNameSearchText(exercise)).toContain(ptBR[exercise.id])
- expect(exerciseNameSearchText(exercise)).toContain(exercise.n)
- })
-
- test('never translates custom exercises or changes other languages', () => {
- const custom = { id: 'custom-1', n: 'Meu exercício' }
- _setLangState('pt-BR', {}, null, ptBR)
- expect(exerciseNameFor(custom)).toBe('Meu exercício')
- _setLangState('en', {}, null, null)
- expect(exerciseNameFor(EXDB[0])).toBe(EXDB[0].n)
- })
-})
diff --git a/frontend/src/lib/pt-br-instructions.test.js b/frontend/src/lib/pt-br-instructions.test.js
index 69993df37..1c393b18e 100644
--- a/frontend/src/lib/pt-br-instructions.test.js
+++ b/frontend/src/lib/pt-br-instructions.test.js
@@ -3,26 +3,24 @@ import { readFileSync } from 'node:fs'
import ptBR from '../instr/pt-BR.js'
import { EXDB } from './exercises-data.js'
import { INSTR_LANGS } from './i18n-core.js'
+import V13_IDS from './catalogue-v13-ids.json' with { type: 'json' }
// English steps live in their own pack since the catalogue moved to catalogue/ (v1.4.0)
import EN from '../instr/en.js'
describe('Brazilian Portuguese exercise instructions', () => {
const exercises = new Map(EXDB.map(exercise => [exercise.id, exercise]))
- const source = JSON.parse(readFileSync(new URL('../../../scripts/instruction-sources/pt-BR.json', import.meta.url), 'utf8'))
+ const catalogue = JSON.parse(readFileSync(new URL('../../../catalogue/i18n/pt-BR.json', import.meta.url), 'utf8'))
- test('matches the curated source and covers the complete exercise corpus', () => {
- expect(Object.keys(ptBR)).toHaveLength(EXDB.length)
- expect(ptBR).toEqual(source)
+ // The v1.3 catalogue was translated in full; the v1.4 additions fall back to English until
+ // someone writes them, so coverage is pinned on the legacy ids only.
+ test('is built from catalogue/i18n and covers the v1.3 catalogue', () => {
+ const steps = Object.fromEntries(Object.entries(catalogue).filter(([, row]) => row.instructions).map(([id, row]) => [id, row.instructions]))
+ expect(ptBR).toEqual(steps)
+ for (const id of V13_IDS) expect(ptBR, id).toHaveProperty(id)
})
- test('only enables pt-BR instructions when the pack is complete', () => {
- expect(INSTR_LANGS.includes('pt-BR')).toBe(Object.keys(ptBR).length === EXDB.length)
- })
-
- test('completes Stage 1 waist and core coverage', () => {
- const stage = EXDB.filter(exercise => exercise.bp === 'waist')
- expect(stage).toHaveLength(169)
- stage.forEach(exercise => expect(ptBR, exercise.id).toHaveProperty(exercise.id))
+ test('enables pt-BR instructions when there is a pack', () => {
+ expect(INSTR_LANGS.includes('pt-BR')).toBe(Object.keys(ptBR).length > 0)
})
test('contains only known exercises with complete, non-empty step lists', () => {
diff --git a/frontend/src/lib/ru-exercise-names.test.js b/frontend/src/lib/ru-exercise-names.test.js
deleted file mode 100644
index 7bc65132b..000000000
--- a/frontend/src/lib/ru-exercise-names.test.js
+++ /dev/null
@@ -1,70 +0,0 @@
-import { afterEach, describe, expect, test } from 'vitest'
-import { readFileSync } from 'node:fs'
-import ru from '../exercise-names/ru.js'
-import { EXDB } from './exercises-data.js'
-import {
- EXERCISE_NAME_LANGS, _setLangState, exerciseNameFor, exerciseNameSearchText
-} from './i18n-core.js'
-
-describe('Russian exercise names', () => {
- const source = JSON.parse(readFileSync(new URL('../../../scripts/exercise-name-sources/ru.json', import.meta.url), 'utf8'))
- afterEach(() => _setLangState('en', {}, null, null))
-
- test('matches the curated source and covers the complete built-in catalogue', () => {
- expect(Object.keys(ru)).toHaveLength(EXDB.length)
- expect(ru).toEqual(source)
- expect(EXERCISE_NAME_LANGS).toContain('ru')
- })
-
- test('contains a non-empty Russian translation for every known exercise', () => {
- for (const exercise of EXDB) {
- expect(ru[exercise.id]?.trim(), exercise.id).toBeTruthy()
- // Cyrillic somewhere in the title: a name left in English would otherwise pass
- // every other check in this file while showing "barbell bench press (barbell bench press)".
- expect(ru[exercise.id], exercise.id).toMatch(/\p{Script=Cyrillic}/u)
- // Transliterated calques the glossary rejects in favour of the term gyms actually use.
- expect(ru[exercise.id], exercise.id).not.toMatch(/(?:^|[^\p{L}])(?:керл|завиток|череполом|хруст|сит-ап|пуш-ап|пул-ап|чин-ап|кеттлбелл|ассистированн\p{L}*|проповедник|мёртвая тяга)(?=$|[^\p{L}])/iu)
- }
- })
-
- test('preserves identity-changing qualifiers and equipment', () => {
- const rules = [
- // "ez bar"/"ez barbell" is the EZ bar, and an olympic barbell is named for the bar too,
- // so a plain "barbell" is the only one that has to say штанга.
- [/ez[\s-]bar/iu, /ez-гриф/iu],
- [/(?<!ez[\s-])(?<!olympic )barbell/iu, /штанг/iu],
- [/olympic barbell/iu, /(?:олимпийск|штанг)/iu],
- [/dumbbell/iu, /гантел/iu],
- [/kettlebell/iu, /гир/iu],
- [/smith/iu, /смит/iu],
- [/trap bar/iu, /трэп-гриф/iu],
- [/stability ball/iu, /фитбол/iu],
- [/medicine ball/iu, /медбол/iu],
- [/assisted/iu, /(?:поддержк|самопомощ)/iu],
- [/weighted/iu, /отягощен/iu],
- [/(?:^|[^\p{L}])male(?=$|[^\p{L}])/iu, /муж/iu],
- [/(?:^|[^\p{L}])female(?=$|[^\p{L}])/iu, /жен/iu],
- ]
- for (const exercise of EXDB) {
- for (const [english, russian] of rules) {
- if (english.test(exercise.n)) expect(ru[exercise.id], `${exercise.id}: ${exercise.n}`).toMatch(russian)
- }
- }
- })
-
- test('shows Russian first and preserves the canonical English title', () => {
- const exercise = EXDB[0]
- _setLangState('ru', {}, null, ru)
- expect(exerciseNameFor(exercise)).toBe(`${ru[exercise.id]} (${exercise.n})`)
- expect(exerciseNameSearchText(exercise)).toContain(ru[exercise.id])
- expect(exerciseNameSearchText(exercise)).toContain(exercise.n)
- })
-
- test('never translates custom exercises or changes other languages', () => {
- const custom = { id: 'custom-1', n: 'Моё упражнение' }
- _setLangState('ru', {}, null, ru)
- expect(exerciseNameFor(custom)).toBe('Моё упражнение')
- _setLangState('en', {}, null, null)
- expect(exerciseNameFor(EXDB[0])).toBe(EXDB[0].n)
- })
-})
diff --git a/frontend/src/lib/zh-tw-instructions.test.js b/frontend/src/lib/zh-tw-instructions.test.js
index 0dd2b096b..1a5d8a053 100644
--- a/frontend/src/lib/zh-tw-instructions.test.js
+++ b/frontend/src/lib/zh-tw-instructions.test.js
@@ -2,14 +2,16 @@ import { describe, expect, test } from 'vitest'
import zhTW from '../instr/zh-TW.js'
import { EXDB } from './exercises-data.js'
import { INSTR_LANGS } from './i18n-core.js'
+import V13_IDS from './catalogue-v13-ids.json' with { type: 'json' }
// English steps live in their own pack since the catalogue moved to catalogue/ (v1.4.0)
import EN from '../instr/en.js'
describe('Traditional Chinese (zh-TW) exercise instructions', () => {
const exercises = new Map(EXDB.map(exercise => [exercise.id, exercise]))
- test('covers the complete exercise corpus of 1324 exercises', () => {
- expect(Object.keys(zhTW)).toHaveLength(EXDB.length)
+ // The v1.3 catalogue was translated in full; the v1.4 additions fall back to English.
+ test('covers the 1324 exercises of the v1.3 catalogue', () => {
+ for (const id of V13_IDS) expect(zhTW, id).toHaveProperty(id)
})
test('enables zh-TW in INSTR_LANGS when there is a pack', () => {
diff --git a/scripts/de-name-rules.mjs b/scripts/de-name-rules.mjs
index 4ce0041e9..e9ce6d58e 100644
--- a/scripts/de-name-rules.mjs
+++ b/scripts/de-name-rules.mjs
@@ -1,6 +1,6 @@
// The German exercise-name rules, in one place. Imported by translate-de-exercise-names.mjs,
// which checks every batch during translation and sends violations back to the model as a
-// correction, and by frontend/src/lib/de-exercise-names.test.js, which fails the build. The two
+// correction, and by frontend/src/lib/exercise-names.test.js, which fails the build. The two
// callers share this definition deliberately: inline copies are how a rule drifts unseen.
//
// Every `fix` quotes the offending word. A generic instruction ("use the German term") is