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.
JavaScript apple-watchbodyweightdockerfitnessfitness-trackergymhealthiosmcpnodejspasskeysprogressive-web-applicationspwareactself-hostedself-hostingvitewebauthnweightliftingworkout-tracker
Merge merge request !16 (pt-BR exercise names and instructions)
Duarte Santos76973edad106
diff --cc frontend/src/lib/exercises.jsindex f4b41d536,27ec70145..1fd24ab10--- a/frontend/src/lib/exercises.js+++ b/frontend/src/lib/exercises.js@@@ -1,5 -1,5 +1,5 @@@import { EXDB } from './exercises-data.js'- import { t, getVersion } from './i18n-core.js'-import { t } from './i18n-core.js'++import { t, getVersion, exerciseNameSearchText } from './i18n-core.js'export { EXDB }@@@ -77,47 -77,3 +77,47 @@@ export const isBodyweightEq = idOrEx =// down on the first `ex.n`.export const exOr = id => EXIDX[id] ||{ id, n: t('Unknown exercise'), bp: '', tg: '', eq: '', sm: [], st: [], missing: true }++// Normalizes text by lowercasing and stripping diacritics/accents (e.g. "elevação" -> "elevacao")+export const normalizeStr = s => (s || '')+ .normalize('NFD')+ .replace(/[\u0300-\u036f]/g, '')+ .toLowerCase()++// Multi-token, accent-insensitive and multilingual exercise search.+// Matches when all whitespace-separated words in the query appear anywhere in the exercise's+// name, equipment, target muscle, body part (both in English and translated to active language),+// secondary muscles or description.+//+// The haystack is built once per exercise and cached: NFD-normalising ~1300 catalogue entries+// on every keystroke costs ~8ms on a desktop and several times that on a phone. The cache key+// is the i18n version (bumped by every setLang), so switching language rebuilds the translated+// terms. Custom exercises are re-cached automatically — the store clones state on update, so an+// edited exercise arrives as a new object the WeakMap has never seen.+const corpusCache = new WeakMap()++function corpusOf(e) {+ const v = getVersion()+ const hit = corpusCache.get(e)+ if (hit && hit.v === v) return hit.s+ const sm = Array.isArray(e?.sm) ? e.sm : []+ const s = normalizeStr([- e?.n || '',++ exerciseNameSearchText(e),+ e?.tg || '', t(e?.tg || ''),+ e?.eq || '', t(e?.eq || ''),+ e?.bp || '', t(e?.bp || ''),+ ...sm, ...sm.map(m => t(m)),+ e?.desc || ''+ ].join(' '))+ corpusCache.set(e, { v, s })+ return s+}++export function matchExercise(e, query) {+ if (!query) return true+ const tokens = normalizeStr(query).split(/\s+/).filter(Boolean)+ if (!tokens.length) return true+ if (!e || typeof e !== 'object') return false+ const corpus = corpusOf(e)+ return tokens.every(tok => corpus.includes(tok))+}diff --cc frontend/src/lib/exercises.test.jsindex b3c7c1c9a,000000000..1bc689753mode 100644,000000..100644--- a/frontend/src/lib/exercises.test.js+++ b/frontend/src/lib/exercises.test.js@@@ -1,100 -1,0 +1,121 @@@+import { describe, it, expect } from 'vitest'+import { matchExercise, normalizeStr } from './exercises.js'+import { _setLangState } from './i18n-core.js'++describe('normalizeStr', () => {+ it('handles null, undefined and empty strings', () => {+ expect(normalizeStr(null)).toBe('')+ expect(normalizeStr(undefined)).toBe('')+ expect(normalizeStr('')).toBe('')+ })++ it('lowercases text and removes diacritics / accents', () => {+ expect(normalizeStr('Elevação Lateral')).toBe('elevacao lateral')+ expect(normalizeStr('SUPINO INCLINADO COM HALTERES')).toBe('supino inclinado com halteres')+ expect(normalizeStr('Tríceps & Panturrilhas')).toBe('triceps & panturrilhas')+ expect(normalizeStr('Quadríceps / Glúteos')).toBe('quadriceps / gluteos')+ })+})++describe('matchExercise', () => {+ const benchPress = {+ id: '0025',+ n: 'barbell bench press',+ bp: 'chest',+ tg: 'pectorals',+ eq: 'barbell',+ sm: ['triceps', 'deltoids'],+ desc: 'Classic chest exercise using a barbell on a flat bench.'+ }++ const lateralRaise = {+ id: '0283',+ n: 'dumbbell lateral raise',+ bp: 'shoulders',+ tg: 'delts',+ eq: 'dumbbell',+ sm: ['traps'],+ desc: 'Shoulder isolation movement.'+ }++ it('returns true for empty or whitespace-only query', () => {+ expect(matchExercise(benchPress, '')).toBe(true)+ expect(matchExercise(benchPress, ' ')).toBe(true)+ expect(matchExercise(benchPress, null)).toBe(true)+ })++ it('matches exact and partial words in exercise name regardless of case', () => {+ expect(matchExercise(benchPress, 'bench')).toBe(true)+ expect(matchExercise(benchPress, 'BENCH')).toBe(true)+ expect(matchExercise(benchPress, 'barbell')).toBe(true)+ expect(matchExercise(benchPress, 'press')).toBe(true)+ expect(matchExercise(benchPress, 'squat')).toBe(false)+ })++ it('matches multiple tokens in ANY order (not just sequential)', () => {+ // "bench barbell" is reversed order compared to "barbell bench press"+ expect(matchExercise(benchPress, 'bench barbell')).toBe(true)+ expect(matchExercise(benchPress, 'press bench barbell')).toBe(true)+ expect(matchExercise(benchPress, 'barbell press chest')).toBe(true)+ expect(matchExercise(benchPress, 'bench squat')).toBe(false)+ })++ it('matches target muscle, equipment, secondary muscles and description', () => {+ expect(matchExercise(benchPress, 'pectorals')).toBe(true)+ expect(matchExercise(benchPress, 'triceps barbell')).toBe(true)+ expect(matchExercise(benchPress, 'flat bench')).toBe(true)+ expect(matchExercise(lateralRaise, 'dumbbell shoulder')).toBe(true)+ })++ it('matches accent-insensitively', () => {+ const customEx = {+ id: 'custom-1',+ n: 'Elevação de Panturrilha',+ bp: 'lower legs',+ tg: 'calves',+ eq: 'body weight',+ desc: 'Exercício para panturrilhas em pé.'+ }++ expect(matchExercise(customEx, 'elevacao')).toBe(true)+ expect(matchExercise(customEx, 'elevação')).toBe(true)+ expect(matchExercise(customEx, 'panturrilha elevacao')).toBe(true)+ expect(matchExercise(customEx, 'ELEVACAO PE')).toBe(true)+ })++ it('matches translated UI terms when a language is active', () => {+ _setLangState('pt', {+ chest: 'peito',+ barbell: 'barra',+ dumbbell: 'halteres',+ shoulders: 'ombros'+ }, null)++ // "peito" is the translated bp, "barra" is the translated eq+ expect(matchExercise(benchPress, 'peito')).toBe(true)+ expect(matchExercise(benchPress, 'barra')).toBe(true)+ expect(matchExercise(benchPress, 'peito barra bench')).toBe(true)+ expect(matchExercise(lateralRaise, 'halteres ombros')).toBe(true)+ })++++ // The pt-BR exercise-name pack (!16) renames the catalogue in the UI. Searching has to reach++ // that name as well as the canonical English one, or the library goes dark for pt-BR profiles++ // the moment they type what they see on screen.++ it('matches the localized exercise name as well as the English one', () => {++ _setLangState('pt-BR', {}, null, { '0025': 'supino reto com barra' })++++ expect(matchExercise(benchPress, 'supino')).toBe(true)++ expect(matchExercise(benchPress, 'supino barra')).toBe(true)++ expect(matchExercise(benchPress, 'bench press')).toBe(true) // English still reaches it++ expect(matchExercise(lateralRaise, 'supino')).toBe(false) // untranslated entry unaffected++ })++++ it('rebuilds the cached haystack when the language changes', () => {++ _setLangState('pt-BR', {}, null, { '0025': 'supino reto com barra' })++ expect(matchExercise(benchPress, 'supino')).toBe(true)++++ _setLangState('en', null, null, null)++ expect(matchExercise(benchPress, 'supino')).toBe(false)++ expect(matchExercise(benchPress, 'bench')).toBe(true)++ })+})diff --cc frontend/src/lib/plan-share.jsindex 8f6263022,1f8bf5215..a24329f3d--- a/frontend/src/lib/plan-share.js+++ b/frontend/src/lib/plan-share.js@@@ -173,10 -172,9 +173,10 @@@ function routineHTML(r, unit)const rows = units(r.ex).map(u => {const items = u.map(e => {const ex = EXIDX[e.id]- const name = ex ? ex.n : t('Unknown exercise')+ const name = ex ? exerciseNameFor(ex) : t('Unknown exercise')const part = ex && ex.bp && ex.bp !== 'cardio' ? `<span class="part">${esc(ex.bp)}</span>` : ''- return `<div class="ex"><div class="ex-n">${esc(name)}${part}</div><div class="ex-s">${esc(scheme(e, unit))}</div></div>`+ const note = e.note ? `<div class="ex-note">${esc(e.note)}</div>` : ''+ return `<div class="ex"><div class="ex-row"><div class="ex-n">${esc(name)}${part}</div><div class="ex-s">${esc(scheme(e, unit))}</div></div>${note}</div>`}).join('')return u.length > 1? `<div class="ss"><div class="ss-tag">${esc(t('Superset'))}</div><div class="ss-items">${items}</div></div>`diff --cc frontend/src/sheets.jsxindex 5b0eb309e,80f1cf5c3..9327b7657--- a/frontend/src/sheets.jsx+++ b/frontend/src/sheets.jsx@@@ -6,7 -5,7 +6,7 @@@ import { activeProfile, exAvailable, ALimport { fmtDate, fmtNum, fmtVol, fmtDur, durPart, todayISO, uid, exCount, DAYN, MONTHS_LONG, ACCENTS } from './lib/format.js'import { lastEntryFor, bestWeightFor, buildSets, effectiveRoutineId, workoutVolume, setsDone, setsDoneActive, lastBW, supersetUnits, unitOf, setLabel, defaultConfig, cleanupSg, modeOf, effortOf, isBw, isPerSide, sideReps, workSetsDone } from './lib/history.js'import { beep, vibrate } from './lib/sound.js'- import { t, instrFor, getLang, INSTR_LANGS } from './lib/i18n.js'-import { t, instrFor, exerciseNameFor, exerciseNameSearchText, getLang, INSTR_LANGS } from './lib/i18n.js'++import { t, instrFor, exerciseNameFor, getLang, INSTR_LANGS } from './lib/i18n.js'import { nav } from './lib/nav.js'import { starterRoutines } from './lib/starter.js'import Media, { Thumb } from './components/Media.jsx'@@@ -422,19 -421,17 +422,19 @@@ function ExercisePicker({ onPick, closconst [q, setQ] = useState('')const [bp, setBp] = useState('') // '' = all, '★' = chosen, else a body partconst [eq, setEq] = useState('') // '' = any equipment+ const [showAll, setShowAll] = useState(false)const [shown, setShown] = useState(50)- const ql = q.toLowerCase().trim()const all = allExercises(st)+ const profile = activeProfile(st)let base = all.filter(e =>(bp === '★' ? usage[e.id] : (!bp || e.bp === bp)) &&- (!ql || exerciseNameSearchText(e).toLowerCase().includes(ql) || e.tg.includes(ql) || e.eq.includes(ql) || (e.desc || '').toLowerCase().includes(ql)))+ matchExercise(e, q))- if (bp === '★') base = [...base].sort((a, b) => (usage[b.id] - usage[a.id]) || (a.n < b.n ? -1 : 1))+ if (bp === '★') base = [...base].sort((a, b) => (usage[b.id] - usage[a.id]) || exerciseNameFor(a).localeCompare(exerciseNameFor(b)))- const eqOpts = equipmentOf(base)+ const eqFiltered = (profile && !showAll) ? base.filter(e => exAvailable(st, e)) : base+ const eqOpts = equipmentOf(eqFiltered)// Drop the equipment filter if the search narrowed it away, so you never hit a dead end.const eqOn = eqOpts.includes(eq) ? eq : ''- const f = eqOn ? base.filter(e => e.eq === eqOn) : base+ const f = eqOn ? eqFiltered.filter(e => e.eq === eqOn) : eqFilteredconst chosenCount = Object.keys(usage).lengthreturn <><h3>{t('Add exercise')}</h3>diff --cc frontend/src/views/Library.jsxindex 0815455a5,37ba9c8f8..4400c2093--- a/frontend/src/views/Library.jsx+++ b/frontend/src/views/Library.jsx@@@ -1,10 -1,9 +1,10 @@@import { useState } from 'react'import { useStore } from '../store/useStore.js'-import { EXDB, BODYPARTS, allExercises, equipmentOf } from '../lib/exercises.js'+import { EXDB, BODYPARTS, allExercises, equipmentOf, matchExercise } from '../lib/exercises.js'+import { activeProfile, exAvailable } from '../lib/equipment.js'import { bestWeightFor } from '../lib/history.js'import { fmtNum } from '../lib/format.js'- import { t } from '../lib/i18n.js'-import { t, exerciseNameFor, exerciseNameSearchText } from '../lib/i18n.js'++import { t, exerciseNameFor } from '../lib/i18n.js'import { Thumb } from '../components/Media.jsx'import { exerciseDetailSheet, addToRoutineSheet, customExSheet } from '../sheets.jsx'import Icon from '../components/Icon.jsx'diff --cc frontend/src/views/RoutineEdit.jsxindex 70433644f,8ff69310c..6b5d92266--- a/frontend/src/views/RoutineEdit.jsx+++ b/frontend/src/views/RoutineEdit.jsx@@@ -2,9 -2,8 +2,9 @@@ import { useNavigate, useParams } fromimport { useEffect } from 'react'import { useStore } from '../store/useStore.js'import { exOr } from '../lib/exercises.js'+import { activeProfile, exAvailable } from '../lib/equipment.js'import { uid } from '../lib/format.js'- import { t } from '../lib/i18n.js'+ import { t, exerciseNameFor } from '../lib/i18n.js'import { supersetUnits, cleanupSg, exLine } from '../lib/history.js'import { Thumb } from '../components/Media.jsx'import { glyphPicker, exercisePicker, exConfigSheet, confirmSheet } from '../sheets.jsx'@@@ -78,9 -67,7 +78,9 @@@ export default function RoutineEdit()exConfigSheet(ex, e, cfg => edit(x => { x[i] = { id: x[i].id, sg: x[i].sg, ...cfg } }), () => edit(x => { x.splice(i, 1); cleanupSg(x) }), r)}}><Thumb ex={ex} />- <div className="grow"><div className="tt capitalize">{ex.n}</div><div className="ss">{exLine(e, S.unit)}</div>- <div className="grow"><div className="tt capitalize">{exerciseNameFor(ex)}</div><div className="ss">{exLine(e, S.unit)}</div></div>++ <div className="grow"><div className="tt capitalize">{exerciseNameFor(ex)}</div><div className="ss">{exLine(e, S.unit)}</div>+ {e.note && <div className="small dim" style={{ marginTop: 2 }}>{e.note}</div>}</div>+ {noEquip && <span className="tag" style={{ color: 'var(--orange)', borderColor: 'var(--orange)' }} title={t('Needs {0} — not in your active profile', t(ex.eq))}><Icon name="warning" /></span>}<div style={{ display: 'flex', flexDirection: 'column', gap: 2, flex: 'none', alignItems: 'center' }}>{i > 0 && <button className={'iconbtn' + (linkedPrev ? ' on-ss' : '')} title={t('Superset with exercise above')} style={{ width: 32, height: 28, borderRadius: 8, fontSize: 15 }} onClick={ev => { ev.stopPropagation(); toggleLink(i) }}><Icon name="link" /></button>}<div style={{ display: 'flex', gap: 2 }}>