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.

Follow-up to #254: the English-name switches work with the German, Spanish and Russian packs too, an English-only name is title-cased again, and the stray ISSUE_ON_GITHUB.md is gone

Duarte Santos0f263a1264f5
diff --git a/ISSUE_ON_GITHUB.md b/ISSUE_ON_GITHUB.md
deleted file mode 100644
index 8be264014..000000000
--- a/ISSUE_ON_GITHUB.md
+++ /dev/null
@@ -1,37 +0,0 @@
-# Exercise-name packs for de/es/fr (and it) plus a per-language "English name in parentheses" toggle
-
-## What problem does this solve?
-
-openGym ships a catalogue of 1,324 built-in exercises with English names. Users who run the
-app in German, Spanish or French (the three most-requested languages after the existing pt-BR,
-hu, it packs) still see every exercise labelled in English — acceptable for a logbook, but the
-rest of the UI is fully translated, and translated exercise names make workouts, plans and
-stats immediately readable without having to mentally map foreign labels.
-
-Separately, the translated exercise names are always followed by the English name in
-parentheses. That is helpful while learning the local term, but it is noise for an experienced
-user who wants a clean, fully-localized list. Today there is no way to turn it off, and no way
-to express the choice *per language* — and no way to fall back to pure English names when even
-the translation is unhelpful.
-
-## Proposed approach
-
-- Add complete exercise-name packs for German, Spanish, French and Italian by translating the
- full 1,324-exercise catalogue. Each pack is authored as a JSON source file and generated by a
- one-off build script that fail-fast on unknown ids, empty values or an incomplete count, with
- a unit test asserting full catalogue coverage plus per-language translation rules.
-- Existing languages without a pack (de-CH is a derived locale and inherits German) keep the
- current behaviour: English names, no toggle.
-- Make the "(English name)" parenthetical a per-language user setting:
- - a persisted per-language map in the client store, defaulting to *shown* so existing
- profiles keep today's rendering;
- - Settings shows a single adaptive switch that reflects the active language (only when that
- language actually has a translated pack, so the option is hidden for languages that cannot
- use it) and remembers a separate choice for each language;
- - the app re-applies the exercise-name rendering when the setting changes.
-- Add a companion **"English names only"** per-language toggle that skips the translation
- entirely and shows the original English name. It is independent of the parenthetical toggle,
- and while either is active the name is shown without the redundant counterpart.
-
-No new dependencies. Training logic (rendering of logged sessions) is a pure helper behind the
-existing i18n seam, covered by unit tests.
\ No newline at end of file
diff --git a/frontend/src/lib/i18n-core.js b/frontend/src/lib/i18n-core.js
index 82fbe5c8c..4ec577335 100644
--- a/frontend/src/lib/i18n-core.js
+++ b/frontend/src/lib/i18n-core.js
@@ -103,10 +103,11 @@ export const exerciseNameFor = ex => {
// That is decided per exercise, not per language: German covers only part of the catalogue,
// and an exercise it has no entry for shows its lower-case English title, which still needs
// the casing ("push-up" would otherwise sit between "Bankdrücken" and "Kniebeuge"). A custom
-// exercise has no pack entry either and keeps the casing it always had.
+// exercise has no pack entry either and keeps the casing it always had, and so does every
+// exercise while "English names only" is on, since exerciseNameFor then shows the English title.
// Callers spread this onto the element that holds exerciseNameFor(ex)'s output, nothing else —
// muscle and equipment labels next to it are t() strings and keep their own capitalize.
-export const exerciseNameClass = ex => (exerciseNames && ex && exerciseNames[ex.id] ? '' : 'capitalize')
+export const exerciseNameClass = ex => (!enOnly && exerciseNames && ex && exerciseNames[ex.id] ? '' : 'capitalize')
// Search both the localized and canonical English title without changing persisted data.
export const exerciseNameSearchText = ex => {
diff --git a/frontend/src/lib/i18n-core.test.js b/frontend/src/lib/i18n-core.test.js
index d5bf15923..7e432e110 100644
--- a/frontend/src/lib/i18n-core.test.js
+++ b/frontend/src/lib/i18n-core.test.js
@@ -1,8 +1,9 @@
import { describe, it, expect } from 'vitest'
import {
LANGS, INSTR_LANGS, EXERCISE_NAME_LANGS, DATE_LOCALES, DERIVED_LOCALES,
- baseLang, derivePack, dateLocale, getLang, t, _setLangState, exerciseNameClass
+ baseLang, derivePack, dateLocale, getLang, t, _setLangState, exerciseNameClass, exerciseNameFor
} from './i18n-core.js'
+import { EXDB } from './exercises-data.js'
import de from '../locales/de.js'
describe('baseLang', () => {
@@ -130,3 +131,45 @@ describe('exerciseNameClass', () => {
_setLangState('en', {}, null, null)
})
})
+
+// The two per-language switches in Settings (the English name in parentheses, English names
+// only) came with the Italian and French packs, but they have to hold for every pack the app
+// ships — German too, which covers only part of the catalogue.
+describe('English-name switches with every exercise-name pack', () => {
+ const packs = import.meta.glob('../exercise-names/*.js', { eager: true, import: 'default' })
+ const packFor = lang => packs[`../exercise-names/${lang}.js`]
+
+ it('ships a pack for every language listed as having one', () => {
+ for (const lang of EXERCISE_NAME_LANGS) expect(packFor(lang), lang).toBeTruthy()
+ })
+
+ for (const lang of EXERCISE_NAME_LANGS) {
+ it(`${lang}: parentheses off shows the translation alone, English only shows the English title`, () => {
+ const names = packFor(lang)
+ const ex = EXDB.find(e => names[e.id] && names[e.id].toLocaleLowerCase(lang) !== e.n.toLocaleLowerCase('en'))
+ expect(ex, lang).toBeTruthy()
+ _setLangState(lang, {}, null, names)
+ expect(exerciseNameFor(ex)).toBe(`${names[ex.id]} (${ex.n})`)
+ expect(exerciseNameClass(ex)).toBe('')
+ _setLangState(lang, {}, null, names, false)
+ expect(exerciseNameFor(ex)).toBe(names[ex.id])
+ expect(exerciseNameClass(ex)).toBe('')
+ _setLangState(lang, {}, null, names, true, true)
+ expect(exerciseNameFor(ex)).toBe(ex.n)
+ // The English title is stored lower-case, so it gets the title-casing back with it.
+ expect(exerciseNameClass(ex)).toBe('capitalize')
+ _setLangState('en', {}, null, null)
+ })
+ }
+
+ it('de: an exercise the partial pack does not cover is unaffected by either switch', () => {
+ const names = packFor('de')
+ const ex = EXDB.find(e => !names[e.id])
+ for (const [showEn, enOnly] of [[true, false], [false, false], [true, true]]) {
+ _setLangState('de', {}, null, names, showEn, enOnly)
+ expect(exerciseNameFor(ex)).toBe(ex.n)
+ expect(exerciseNameClass(ex)).toBe('capitalize')
+ }
+ _setLangState('en', {}, null, null)
+ })
+})
diff --git a/frontend/src/views/Settings.jsx b/frontend/src/views/Settings.jsx
index d38934c88..6f78050d1 100644
--- a/frontend/src/views/Settings.jsx
+++ b/frontend/src/views/Settings.jsx
@@ -257,13 +257,13 @@ export default function Settings() {
}))}
/>
{EXERCISE_NAME_LANGS.includes(baseLang(S.lang || 'en')) && <>
- <Row icon="textHeight" iconTint="var(--purple)" title={t('English exercise names')}
+ <Row icon="dumbbell" iconTint="var(--purple)" title={t('English exercise names')}
subtitle={t('Show the English name in parentheses next to the translated one.')}>
<Switch checked={S.enParens?.[baseLang(S.lang || 'en')] ?? true}
disabled={S.enOnly?.[baseLang(S.lang || 'en')] === true}
onChange={v => update(s => { s.enParens = { ...(s.enParens || {}), [baseLang(S.lang || 'en')]: v } })} />
</Row>
- <Row icon="textHeight" iconTint="var(--purple)" title={t('English names only')}
+ <Row icon="globe" iconTint="var(--purple)" title={t('English names only')}
subtitle={t('Replace the translated names with the original English ones.')}>
<Switch checked={S.enOnly?.[baseLang(S.lang || 'en')] === true}
onChange={v => update(s => { s.enOnly = { ...(s.enOnly || {}), [baseLang(S.lang || 'en')]: v } })} />