feat(i18n): localize pt-BR exercise names
This commit is contained in:
1 parent
dc3fafc6ef
commit
448c66752f
21 files changed
+1615
-53
No files matched your search
+3
-1
@@ -118,7 +118,9 @@ animations are © Gym visual, not CC, which matters if you redistribute them.
|
||||
|
||||
- 🇧🇷 **Brazilian Portuguese UI** — Portuguese now has separate Portugal and
|
||||
Brazil options, with Brazilian terminology, date formatting and localized
|
||||
instructions for all 1,324 exercises.
|
||||
instructions for all 1,324 exercises. Built-in exercise titles show the
|
||||
Brazilian Portuguese name followed by the canonical English name, so both
|
||||
vocabularies remain recognizable and searchable.
|
||||
|
||||
### Fixes
|
||||
|
||||
|
||||
@@ -117,8 +117,9 @@ If you want to reuse the media — in openGym or anywhere else, commercially or
|
||||
the rights holder first**, and keep any attribution that accompanies it intact.
|
||||
|
||||
Brazilian Portuguese exercise instructions under
|
||||
`scripts/instruction-sources/pt-BR.json` are original translations of that
|
||||
`scripts/instruction-sources/pt-BR.json` and exercise names under
|
||||
`scripts/exercise-name-sources/pt-BR.json` are original translations of that
|
||||
English source produced with OpenAI Codex and Anthropic Claude Code
|
||||
language-model assistance. They are not copied from a separate Portuguese
|
||||
dataset. Their review status and translation policy are documented alongside
|
||||
the source file.
|
||||
the source files.
|
||||
@@ -84,7 +84,7 @@ as a home-screen app, passkey sign-in, offline support, sync across your phone a
|
||||
- 🔑 **Passkeys, not passwords** — Face ID / Touch ID / fingerprint login; each profile keeps its own data, synced across devices. Sign-ins last 90 days by default (configurable), and “sign out everywhere” in Settings ends every session on every device at once
|
||||
- 🛠️ **Admin dashboard** (optional) — for whoever runs the instance: who's training right now, per-user history, disable accounts, invite-only signup, and an **activity log** of sign-ins, failed attempts and admin actions. Off by default, so a fresh instance stays open with no admin
|
||||
- 🎨 **Designed, not assembled** — light/dark themes and 8 accent colors saved to your profile, over a hand-drawn icon set instead of emoji, so it looks the same on every phone
|
||||
- 🌍 **13 languages** — full UI translation (EN, DE, ES, FR, IT, PT (Portugal), PT (Brazil), PL, TR, RU, ZH, KO, HI); exercise instructions localized in 11 of them, loaded on demand so the app stays fast
|
||||
- 🌍 **13 languages** — full UI translation (EN, DE, ES, FR, IT, PT (Portugal), PT (Brazil), PL, TR, RU, ZH, KO, HI); exercise instructions localized in 11 of them and built-in exercise names shown bilingually in PT-BR, all loaded on demand so the app stays fast
|
||||
- 📥 **Bring your history with you** — import from **FitNotes** (Android and iOS), **Strong** and **Hevy**, or body weight straight out of an **Apple Health** export. Exercise names are matched against the library and anything unrecognised becomes one of your own exercises, so nothing in the file is dropped
|
||||
- 📦 **Yours to keep** — one-tap JSON export/import, guest mode, **no telemetry**
|
||||
- 🤖 **Ask an AI about your training** (optional) — an [MCP server](mcp/README.md) lets a client like Claude Desktop or Cursor read your history in your own words: *"what did I bench last week?"*. Read-only, spawned locally by the client, nothing leaves your box. Not in the Docker build — if you don't use an AI assistant, it isn't there
|
||||
@@ -201,7 +201,7 @@ Rough, community-driven — ideas and PRs welcome:
|
||||
- [x] Effort per set — RIR or RPE, whichever scale you think in
|
||||
- [ ] Body measurements (waist, arms…) alongside weight
|
||||
- [ ] Per-exercise notes & plate calculator
|
||||
- [ ] Exercise instructions in German & Portuguese (UI is translated; upstream dataset doesn't ship these yet)
|
||||
- [ ] Exercise instructions in German & Portuguese (Portugal); the separately curated Brazilian Portuguese pack is complete
|
||||
|
||||
## Tech
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useState } from 'react'
|
||||
import { imgSrc, gifSrc } from '../lib/exercises.js'
|
||||
import { useStore } from '../store/useStore.js'
|
||||
import { t } from '../lib/i18n.js'
|
||||
import { t, exerciseNameFor } from '../lib/i18n.js'
|
||||
import Icon from './Icon.jsx'
|
||||
|
||||
// Big autoplaying animation; tap toggles to the still frame. `compact` shrinks it (superset cards).
|
||||
@@ -18,7 +18,7 @@ export default function Media({ ex, id, compact, minimizable }) {
|
||||
const toggleSize = e => { e.stopPropagation(); update(s => { s.gifSize = mini ? 'full' : 'mini' }) }
|
||||
return (
|
||||
<div className={'exmedia' + (compact ? ' compact' : '') + (mini ? ' mini' : '')} id={id} onClick={() => setPlaying(p => !p)}>
|
||||
<img decoding="async" src={playing ? gifSrc(ex) : imgSrc(ex)} alt={ex.n} />
|
||||
<img decoding="async" src={playing ? gifSrc(ex) : imgSrc(ex)} alt={exerciseNameFor(ex)} />
|
||||
{minimizable && (
|
||||
<button className="giftoggle" onClick={toggleSize}>
|
||||
<Icon name={mini ? 'expand' : 'minimize'} />{mini ? t('Expand') : t('Minimize')}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
// generated by scripts/build-pt-br-exercise-names.mjs — edit scripts/exercise-name-sources/pt-BR.json
|
||||
export default {"1000":"elevação de panturrilha invertida unilateral com faixa elástica","1001":"afundo estático unilateral com faixa elástica","1002":"elevação de pernas retas deitado com faixa elástica","1003":"agachamento com remada e faixa elástica","1004":"agachamento com faixa elástica","1005":"abdominal em pé com faixa elástica","1007":"abdominal rotacional em pé com faixa elástica","1008":"subida no step com faixa elástica","1009":"levantamento terra pernas semiestendidas com faixa elástica","1010":"levantamento terra pernas estendidas com faixa elástica","1011":"torção sentado com faixa elástica","1012":"desenvolvimento acima da cabeça com rotação e faixa elástica","1013":"puxada pegada supinada com faixa elástica","1014":"abdominal em v com faixa elástica","1015":"pallof press vertical com faixa elástica","1016":"rosca de punho com faixa elástica","1017":"elevação em y com faixa elástica","1018":"encolhimento de ombros com faixa elástica","1022":"remada para deltoide posterior em pé com faixa elástica","1023":"levantamento terra pernas semiestendidas com costas retas e faixa elástica","1160":"burpee","1167":"alongamento dinâmico de peitoral (masculino)","1201":"Burpee com halteres","1253":"elevação de panturrilha burro na máquina","1254":"supino com faixa elástica","1255":"pullover declinado com barra","1256":"supino declinado pegada supinada com barra","1257":"supino inclinado pegada supinada com barra","1258":"supino pegada aberta supinada com barra","1259":"alongamento de peitoral atrás da cabeça","1260":"supino declinado unilateral no cabo","1261":"supino declinado no cabo","1262":"crucifixo declinado unilateral no cabo","1263":"crucifixo unilateral na bola de exercício no cabo","1264":"crucifixo inclinado unilateral na bola de exercício no cabo","1265":"supino inclinado unilateral no cabo","1266":"supino inclinado unilateral na bola de exercício no cabo","1267":"supino unilateral na bola de exercício no cabo","1268":"supino na bola de exercício no cabo","1269":"crossover em pé ereto no cabo","1270":"crossover para peitoral superior no cabo","1271":"alongamento de peito e parte frontal do ombro","1272":"alongamento de peito com bola de exercício","1273":"flexão de braços com palma","1274":"flexão de braços profunda","1275":"flexão de braços com queda","1276":"Crucifixo declinado unilateral com halter","1277":"Crucifixo com halteres na bola de estabilidade","1278":"Crucifixo inclinado com halteres na bola de estabilidade","1279":"Crucifixo inclinado unilateral com halter","1280":"Crucifixo inclinado unilateral com halter na bola de estabilidade","1281":"Supino inclinado unilateral com halter","1282":"Supino inclinado unilateral com halter na bola de estabilidade","1283":"Supino inclinado com halteres na bola de estabilidade","1284":"Pullover deitado na bola de estabilidade com halter","1285":"Crucifixo unilateral no banco com halter","1286":"Crucifixo unilateral na bola de estabilidade com halter","1287":"Supino declinado unilateral com halter","1288":"Crucifixo unilateral na bola de estabilidade com halter","1289":"Supino inclinado unilateral com halter","1290":"Supino unilateral na bola de estabilidade com halter","1291":"Pullover unilateral na bola de estabilidade com halter","1292":"Crucifixo com uma perna na bola de estabilidade (halteres)","1293":"Supino na bola de estabilidade com halteres","1294":"Pullover com extensão de quadril na bola de estabilidade (halteres)","1295":"Pullover na bola de estabilidade com halteres","1296":"flexão de braços em pique na bola de estabilidade","1297":"contração isométrica de peitoral","1298":"supino unilateral com kettlebell no chão","1299":"supino inclinado na máquina","1300":"supino declinado na máquina","1301":"supino interno na máquina","1302":"passe de peito com bola medicinal","1303":"empurrão de peito com bola medicinal a partir de três apoios","1304":"empurrão de peito com bola medicinal (resposta múltipla)","1305":"empurrão de peito com bola medicinal (resposta única)","1306":"flexão de braços pliométrica","1307":"flexão de braços na bosu","1308":"supino pegada aberta na máquina Smith","1309":"supino declinado pegada aberta na máquina Smith","1310":"flexão de braços com queda e peso","1311":"flexão de braços com mãos afastadas","1312":"empurrão de peito com bola medicinal com saída em corrida","1313":"remada unilateral na máquina","1314":"extensão de tronco na bola de estabilidade","1316":"pullover com braços flexionados com barra","1317":"remada no banco inclinado pegada supinada com barra","1318":"remada no banco inclinado no cabo","1319":"remada com rotação da palma no cabo","1320":"remada sentada crossover com corda no cabo","1321":"remada sentada elevada com corda no cabo","1322":"remada no banco inclinado com extensão de corda no cabo","1323":"remada sentada com corda no cabo","1324":"remada superior no cabo","1325":"puxada atrás da nuca pegada abLine truncated
|
||||
@@ -1,5 +1,6 @@
|
||||
// Runtime-agnostic core of the i18n module: state, constants and readers (t, dateLocale,
|
||||
// instrFor, getLang). Plain Node-loadable — the browser-only pieces (import.meta.glob lazy
|
||||
// instrFor, exerciseNameFor, getLang). Plain Node-loadable — the browser-only pieces
|
||||
// (import.meta.glob lazy
|
||||
// loads, the React subscription hook) live in i18n.js and re-export from here.
|
||||
|
||||
export const LANGS = {
|
||||
@@ -9,6 +10,7 @@ export const LANGS = {
|
||||
ko: '한국어', hi: 'हिन्दी'
|
||||
}
|
||||
export const INSTR_LANGS = ['en', 'es', 'fr', 'it', 'tr', 'ru', 'zh', 'hi', 'pl', 'ko', 'pt-BR']
|
||||
export const EXERCISE_NAME_LANGS = ['pt-BR']
|
||||
export const DATE_LOCALES = {
|
||||
en: 'en-GB', de: 'de-DE', es: 'es-ES', fr: 'fr-FR', it: 'it-IT', pt: 'pt-PT', 'pt-BR': 'pt-BR',
|
||||
pl: 'pl-PL', tr: 'tr-TR', ru: 'ru-RU', zh: 'zh-CN', ko: 'ko-KR', hi: 'hi-IN'
|
||||
@@ -17,6 +19,7 @@ export const DATE_LOCALES = {
|
||||
let lang = 'en' // set only by _setLangState, called from i18n.js setLang
|
||||
let dict = {} // current locale pack (empty = English fallback)
|
||||
let instr = null // { exId: [steps] } for the current language, null = English
|
||||
let exerciseNames = null // { exId: translated name }, null = original catalogue name
|
||||
let version = 0 // bumped on every setLang; drives the React subscription selector
|
||||
|
||||
export const getLang = () => lang
|
||||
@@ -33,13 +36,32 @@ export function t(s, ...args) {
|
||||
// Instructions for an exercise in the current language (English steps as fallback).
|
||||
export const instrFor = ex => (instr && instr[ex.id]) || ex.st || []
|
||||
|
||||
// Built-in catalogue names are bilingual when a complete translated name pack is active.
|
||||
// User-created exercises have no entry in the pack and keep their exact chosen name.
|
||||
export const exerciseNameFor = ex => {
|
||||
const translated = exerciseNames && ex && exerciseNames[ex.id]
|
||||
if (!translated) return ex?.n || ''
|
||||
// Some names (Burpee, Pilates, brand/model terms) are the established pt-BR term too.
|
||||
// Repeating an identical loanword in parentheses adds noise rather than context.
|
||||
return translated.toLocaleLowerCase('pt-BR') === ex.n.toLocaleLowerCase('en')
|
||||
? translated
|
||||
: `${translated} (${ex.n})`
|
||||
}
|
||||
|
||||
// Search both the localized and canonical English title without changing persisted data.
|
||||
export const exerciseNameSearchText = ex => {
|
||||
const translated = exerciseNames && ex && exerciseNames[ex.id]
|
||||
return translated ? `${translated} ${ex.n}` : (ex?.n || '')
|
||||
}
|
||||
|
||||
// Called by i18n.js's setLang once the locale pack has been loaded — kept here rather than
|
||||
// exported as setLang because loading packs requires import.meta.glob, which is Vite-only.
|
||||
// Both `dict` and `instr` may be null to reset to English.
|
||||
export function _setLangState(newLang, newDict, newInstr) {
|
||||
// `dict`, `instr` and `exerciseNames` may be null to reset to their English fallbacks.
|
||||
export function _setLangState(newLang, newDict, newInstr, newExerciseNames) {
|
||||
lang = LANGS[newLang] ? newLang : 'en'
|
||||
dict = lang === 'en' ? {} : (newDict || {})
|
||||
instr = lang === 'en' || !INSTR_LANGS.includes(lang) ? null : (newInstr || null)
|
||||
exerciseNames = lang === 'en' || !EXERCISE_NAME_LANGS.includes(lang) ? null : (newExerciseNames || null)
|
||||
version++
|
||||
return version
|
||||
}
|
||||
+17
-10
@@ -5,16 +5,20 @@
|
||||
|
||||
import { useSyncExternalStore } from 'react'
|
||||
import {
|
||||
LANGS, INSTR_LANGS, DATE_LOCALES,
|
||||
getLang, dateLocale, t, instrFor, getVersion, _setLangState
|
||||
LANGS, INSTR_LANGS, EXERCISE_NAME_LANGS, DATE_LOCALES,
|
||||
getLang, dateLocale, t, instrFor, exerciseNameFor, exerciseNameSearchText, getVersion, _setLangState
|
||||
} from './i18n-core.js'
|
||||
|
||||
export { LANGS, INSTR_LANGS, DATE_LOCALES, getLang, dateLocale, t, instrFor }
|
||||
export {
|
||||
LANGS, INSTR_LANGS, EXERCISE_NAME_LANGS, DATE_LOCALES,
|
||||
getLang, dateLocale, t, instrFor, exerciseNameFor, exerciseNameSearchText
|
||||
}
|
||||
|
||||
// Vite code-splits each locale pack into its own chunk via import.meta.glob; instructions use
|
||||
// the same mechanism in src/instr/. Both are lazy, so the production bundle ships English only.
|
||||
// Vite code-splits locale, instruction and exercise-name packs via import.meta.glob. They are
|
||||
// lazy, so the production bundle ships English only until another language is selected.
|
||||
const localePacks = import.meta.glob('../locales/*.js')
|
||||
const instrPacks = import.meta.glob('../instr/*.js')
|
||||
const exerciseNamePacks = import.meta.glob('../exercise-names/*.js')
|
||||
|
||||
// React subscription bookkeeping — kept here, not in core, so core has zero React coupling.
|
||||
const subs = new Set()
|
||||
@@ -23,12 +27,15 @@ const notify = () => { subs.forEach(f => f()) }
|
||||
export async function setLang(l) {
|
||||
if (!LANGS[l]) l = 'en'
|
||||
if (l === getLang() && getVersion() > 0) return
|
||||
let dict = {}, instr = null
|
||||
let dict = {}, instr = null, exerciseNames = null
|
||||
try { dict = l === 'en' ? {} : (await localePacks['../locales/' + l + '.js']()).default } catch (e) { dict = {} }
|
||||
try { instr = l === 'en' || !INSTR_LANGS.includes(l) ? null : (await instrPacks['../instr/' + l + '.js']()).default } catch (e) { instr = null }
|
||||
try {
|
||||
dict = l === 'en' ? {} : (await localePacks['../locales/' + l + '.js']()).default
|
||||
instr = l === 'en' || !INSTR_LANGS.includes(l) ? null : (await instrPacks['../instr/' + l + '.js']()).default
|
||||
} catch (e) { dict = {}; instr = null }
|
||||
_setLangState(l, dict, instr)
|
||||
exerciseNames = l === 'en' || !EXERCISE_NAME_LANGS.includes(l)
|
||||
? null
|
||||
: (await exerciseNamePacks['../exercise-names/' + l + '.js']()).default
|
||||
} catch (e) { exerciseNames = null }
|
||||
_setLangState(l, dict, instr, exerciseNames)
|
||||
notify()
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
import { EXIDX, isBodyweightEq } from './exercises.js'
|
||||
import { modeOf, fmtSec, isBw, isPerSide, sideReps } from './history.js'
|
||||
import { uid, todayISO, DAYN, fmtNum, exCount } from './format.js'
|
||||
import { t } from './i18n-core.js'
|
||||
import { t, exerciseNameFor } from './i18n-core.js'
|
||||
|
||||
const PLAN_FMT = 1
|
||||
const WEEK_ORDER = [1, 2, 3, 4, 5, 6, 0] // Mon-first, matching the Plan screen
|
||||
@@ -172,7 +172,7 @@ 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>`
|
||||
}).join('')
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
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)
|
||||
})
|
||||
})
|
||||
@@ -11,6 +11,7 @@ import { STRENGTH_FULL_MS, STRENGTH_HALF_LIFE_MS, STRENGTH_FLOOR, halfLifeDecay
|
||||
import { musclesOf } from './muscles.js'
|
||||
import { EXIDX } from './exercises.js'
|
||||
import { isWarmupRow } from './workout-model.js'
|
||||
import { exerciseNameFor } from './i18n-core.js'
|
||||
|
||||
const round1 = value => Math.round(value * 10) / 10
|
||||
|
||||
@@ -61,11 +62,11 @@ export function primaryMuscleOf(entry) {
|
||||
return best
|
||||
}
|
||||
|
||||
function exerciseName(entry) {
|
||||
function resolvedExerciseName(entry) {
|
||||
// Imported history often has no name snapshot (entries are { id, sets, topW }) - the
|
||||
// catalogue (or the registered custom) is the canonical name source.
|
||||
const ex = entry && typeof entry === 'object' ? EXIDX[entry.id] : null
|
||||
if (ex?.n) return ex.n
|
||||
if (ex?.n) return exerciseNameFor(ex)
|
||||
if (entry?.muscleSnapshot?.n) return entry.muscleSnapshot.n
|
||||
return entry && typeof entry === 'object' && entry.n ? entry.n : null
|
||||
}
|
||||
@@ -97,7 +98,7 @@ export function strengthExerciseRows(S, now) {
|
||||
const decay = lastAt == null ? STRENGTH_FLOOR : strengthFromAge(Number(now) - lastAt)
|
||||
rows.push({
|
||||
id,
|
||||
name: exerciseName(entry) || id,
|
||||
name: resolvedExerciseName(entry) || id,
|
||||
est: best.est,
|
||||
estDate: best.d,
|
||||
primary: primaryMuscleOf(entry) ? primaryMuscleOf(entry).slug : null,
|
||||
@@ -129,7 +130,7 @@ export function strengthExerciseRowsForMuscle(S, now, slug) {
|
||||
const primary = primaryMuscleOf(entry)
|
||||
seen.set(entry.id, {
|
||||
id: entry.id,
|
||||
name: exerciseName(entry) || entry.id,
|
||||
name: resolvedExerciseName(entry) || entry.id,
|
||||
weight,
|
||||
primary: primary ? primary.slug : null,
|
||||
est: best.est,
|
||||
|
||||
+12
-12
@@ -5,7 +5,7 @@ import { EXDB, EXIDX, BODYPARTS, isCardio, isBodyweightEq, allExercises, equipme
|
||||
import { 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 { nav } from './lib/nav.js'
|
||||
import { starterRoutines } from './lib/starter.js'
|
||||
import Media, { Thumb } from './components/Media.jsx'
|
||||
@@ -287,7 +287,7 @@ function ExerciseDetail({ ex, close }) {
|
||||
const last = lastEntryFor(st, ex.id)
|
||||
const best = bestWeightFor(st, ex.id)
|
||||
return <>
|
||||
<h3 className="capitalize">{ex.n}</h3>
|
||||
<h3 className="capitalize">{exerciseNameFor(ex)}</h3>
|
||||
<Media ex={ex} />
|
||||
<div className="row" style={{ gap: 6, flexWrap: 'wrap', margin: '10px 0' }}>
|
||||
<span className="tag acc">{t(ex.bp)}</span>
|
||||
@@ -321,12 +321,12 @@ function AddToRoutine({ ex, close }) {
|
||||
if (r) r.ex.push({ id: ex.id, ...cfg })
|
||||
})
|
||||
const r = isNew ? S().routines[S().routines.length - 1] : st.routines.find(x => x.id === rid)
|
||||
toast(t('“{0}” added to {1}', ex.n, r ? r.name : t('routine')))
|
||||
toast(t('“{0}” added to {1}', exerciseNameFor(ex), r ? r.name : t('routine')))
|
||||
if (isNew && r) nav('/plan/r/' + r.id)
|
||||
}, null, isNew ? null : st.routines.find(x => x.id === rid))
|
||||
}
|
||||
return <>
|
||||
<h3 className="capitalize">{t('Add “{0}”', ex.n)}</h3>
|
||||
<h3 className="capitalize">{t('Add “{0}”', exerciseNameFor(ex))}</h3>
|
||||
<div className="muted small" style={{ marginBottom: 12 }}>{t('Pick a routine — sets, reps & weight come next.')}</div>
|
||||
<div className="list">
|
||||
{st.routines.map(r => <div key={r.id} className="item" onClick={() => pick(r.id)}>
|
||||
@@ -426,8 +426,8 @@ function ExercisePicker({ onPick, close }) {
|
||||
const all = allExercises(st)
|
||||
let base = all.filter(e =>
|
||||
(bp === '★' ? usage[e.id] : (!bp || e.bp === bp)) &&
|
||||
(!ql || e.n.toLowerCase().includes(ql) || e.tg.includes(ql) || e.eq.includes(ql) || (e.desc || '').toLowerCase().includes(ql)))
|
||||
if (bp === '★') base = [...base].sort((a, b) => (usage[b.id] - usage[a.id]) || (a.n < b.n ? -1 : 1))
|
||||
(!ql || exerciseNameSearchText(e).toLowerCase().includes(ql) || e.tg.includes(ql) || e.eq.includes(ql) || (e.desc || '').toLowerCase().includes(ql)))
|
||||
if (bp === '★') base = [...base].sort((a, b) => (usage[b.id] - usage[a.id]) || exerciseNameFor(a).localeCompare(exerciseNameFor(b)))
|
||||
const eqOpts = equipmentOf(base)
|
||||
// Drop the equipment filter if the search narrowed it away, so you never hit a dead end.
|
||||
const eqOn = eqOpts.includes(eq) ? eq : ''
|
||||
@@ -452,7 +452,7 @@ function ExercisePicker({ onPick, close }) {
|
||||
<div className="grow"><div className="tt">{t('Create your own exercise')}</div><div className="ss">{t('name + body part, no animation')}</div></div><Icon name="plus" className="chev" />
|
||||
</div>}
|
||||
{f.slice(0, shown).map(e => <div key={e.id} className="item" onClick={() => onPick(e)}>
|
||||
<Thumb ex={e} /><div className="grow"><div className="tt capitalize">{e.n}</div><div className="ss capitalize">{t(e.tg || e.bp)} · {t(e.eq)}</div></div>
|
||||
<Thumb ex={e} /><div className="grow"><div className="tt capitalize">{exerciseNameFor(e)}</div><div className="ss capitalize">{t(e.tg || e.bp)} · {t(e.eq)}</div></div>
|
||||
{usage[e.id] && <span className="tag acc"><Icon name="starFill" /></span>}<Icon name="plus" className="chev" />
|
||||
</div>)}
|
||||
{f.length === 0 && bp === '★' && <div className="empty">{t('Nothing chosen yet — add exercises and they’ll show up here.')}</div>}
|
||||
@@ -531,7 +531,7 @@ function ExConfig({ ex, existing, onSave, onDelete, close, routine, initial }) {
|
||||
}
|
||||
}
|
||||
return <>
|
||||
<h3 className="capitalize">{ex.n}</h3>
|
||||
<h3 className="capitalize">{exerciseNameFor(ex)}</h3>
|
||||
<Media ex={ex} />
|
||||
<div className="row" style={{ gap: 6, flexWrap: 'wrap', margin: '10px 0 14px' }}>
|
||||
{cardio && <span className="tag acc"><Icon name="figureRun" />{t('Cardio')}</span>}
|
||||
@@ -762,7 +762,7 @@ function WorkoutDetail({ w, close }) {
|
||||
const ex = EXIDX[e.id]
|
||||
return <div key={i} className="row" style={{ marginBottom: 12, alignItems: 'flex-start' }}>
|
||||
{ex && <Thumb ex={ex} />}
|
||||
<div className="grow"><div className="tt capitalize" style={{ fontWeight: 600 }}>{ex ? ex.n : (e.n || e.id)} {w.prs && w.prs.includes(e.id) && <span className="pr"><Icon name="trophy" />PR</span>}</div>
|
||||
<div className="grow"><div className="tt capitalize" style={{ fontWeight: 600 }}>{ex ? exerciseNameFor(ex) : (e.n || e.id)} {w.prs && w.prs.includes(e.id) && <span className="pr"><Icon name="trophy" />PR</span>}</div>
|
||||
<div className="ss">{e.sets.filter(s => s.done).map(s => setLabel(e.id, s, e.target)).join(' · ') || t('no sets')}</div></div>
|
||||
</div>
|
||||
})}
|
||||
@@ -883,7 +883,7 @@ function TopWeight({ entryIdx, close }) {
|
||||
} else toast(t('Tracked — next time starts at {0}', fmtNum(S().exWeights[entry.id].w) + ' ' + st.unit))
|
||||
}
|
||||
return <>
|
||||
<h3 className="capitalize row" style={{ gap: 8 }}><Icon name="checkCircle" style={{ color: 'var(--acc)' }} />{t('{0} done', ex.n)}</h3>
|
||||
<h3 className="capitalize row" style={{ gap: 8 }}><Icon name="checkCircle" style={{ color: 'var(--acc)' }} />{t('{0} done', exerciseNameFor(ex))}</h3>
|
||||
<div className="muted small">{t('Confirm the weight you worked with — your highest becomes the default next time.')}{!unitDone && unit.length > 1 ? ' ' + t('Then finish the superset partner.') : ''}</div>
|
||||
<WeightInput value={v} setValue={setV} unit={st.unit} />
|
||||
<div style={{ height: 10 }} />
|
||||
@@ -921,8 +921,8 @@ function FinishSummary({ w, prs, e1prs = [], close }) {
|
||||
<div className="tile"><div className="l">{t('PRs')}</div><div className="v" style={{ fontSize: 20 }}>{prs.length || '—'}</div></div>
|
||||
</div>
|
||||
{(prs.length > 0 || e1prs.length > 0) && <div style={{ textAlign: 'left', marginBottom: 12 }}>
|
||||
{prs.map(id => <div key={id} className="small accent capitalize row" style={{ gap: 5 }}><Icon name="trophy" style={{ fontSize: 13 }} />{t('New PR:')} {(EXIDX[id] || {}).n || id}</div>)}
|
||||
{e1prs.map(p => <div key={p.id} className="small accent capitalize row" style={{ gap: 5 }}><Icon name="chartLine" style={{ fontSize: 13 }} />{t('Best estimated 1RM:')} {(EXIDX[p.id] || {}).n || p.id} · {fmtNum(p.est)} {st.unit}</div>)}
|
||||
{prs.map(id => <div key={id} className="small accent capitalize row" style={{ gap: 5 }}><Icon name="trophy" style={{ fontSize: 13 }} />{t('New PR:')} {EXIDX[id] ? exerciseNameFor(EXIDX[id]) : id}</div>)}
|
||||
{e1prs.map(p => <div key={p.id} className="small accent capitalize row" style={{ gap: 5 }}><Icon name="chartLine" style={{ fontSize: 13 }} />{t('Best estimated 1RM:')} {EXIDX[p.id] ? exerciseNameFor(EXIDX[p.id]) : p.id} · {fmtNum(p.est)} {st.unit}</div>)}
|
||||
</div>}
|
||||
<h4 className="sec" style={{ textAlign: 'left' }}>{t('What you just trained')}</h4>
|
||||
<BodyMap load={loadOfWorkouts([w])} body={st.body} />
|
||||
|
||||
@@ -3,7 +3,7 @@ import { useStore } from '../store/useStore.js'
|
||||
import { EXDB, BODYPARTS, allExercises, equipmentOf } from '../lib/exercises.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 { Thumb } from '../components/Media.jsx'
|
||||
import { exerciseDetailSheet, addToRoutineSheet, customExSheet } from '../sheets.jsx'
|
||||
import Icon from '../components/Icon.jsx'
|
||||
@@ -16,7 +16,7 @@ export default function Library() {
|
||||
const [eq, setEq] = useState('')
|
||||
const [shown, setShown] = useState(40)
|
||||
const ql = q.toLowerCase().trim()
|
||||
const base = allExercises(S).filter(e => (!bp || e.bp === bp) && (!ql || e.n.toLowerCase().includes(ql) || e.tg.includes(ql) || e.eq.includes(ql) || (e.desc || '').toLowerCase().includes(ql)))
|
||||
const base = allExercises(S).filter(e => (!bp || e.bp === bp) && (!ql || exerciseNameSearchText(e).toLowerCase().includes(ql) || e.tg.includes(ql) || e.eq.includes(ql) || (e.desc || '').toLowerCase().includes(ql)))
|
||||
const eqOpts = equipmentOf(base)
|
||||
// Drop the equipment filter if the search narrowed it away, so you never hit a dead end.
|
||||
const eqOn = eqOpts.includes(eq) ? eq : ''
|
||||
@@ -43,7 +43,7 @@ export default function Library() {
|
||||
const best = bestWeightFor(S, e.id)
|
||||
return <div key={e.id} className="item" onClick={() => exerciseDetailSheet(e)}>
|
||||
<Thumb ex={e} />
|
||||
<div className="grow"><div className="tt capitalize">{e.n}</div><div className="ss capitalize">{t(e.tg || e.bp)} · {t(e.eq)}</div></div>
|
||||
<div className="grow"><div className="tt capitalize">{exerciseNameFor(e)}</div><div className="ss capitalize">{t(e.tg || e.bp)} · {t(e.eq)}</div></div>
|
||||
{best > 0 && <span className="tag acc">{fmtNum(best)}</span>}
|
||||
<Button size="sm" variant="tinted" icon="plus" onClick={ev => { ev.stopPropagation(); addToRoutineSheet(e) }}>{t('Plan')}</Button>
|
||||
</div>
|
||||
|
||||
@@ -3,7 +3,7 @@ import { useEffect } from 'react'
|
||||
import { useStore } from '../store/useStore.js'
|
||||
import { exOr } from '../lib/exercises.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'
|
||||
@@ -67,7 +67,7 @@ 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>
|
||||
<div className="grow"><div className="tt capitalize">{exerciseNameFor(ex)}</div><div className="ss">{exLine(e, S.unit)}</div></div>
|
||||
<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 }}>
|
||||
|
||||
@@ -4,7 +4,7 @@ import { useStore } from '../store/useStore.js'
|
||||
import { EXIDX } from '../lib/exercises.js'
|
||||
import { lastBW, streakWeeks, setLabel, modeOf, effortOf, metricModeForEntry, metricRowsForEntry, bestWeightForEntry } from '../lib/history.js'
|
||||
import { fmtNum, fmtDate, fmtVol, todayISO, weekKey } from '../lib/format.js'
|
||||
import { t } from '../lib/i18n.js'
|
||||
import { t, exerciseNameFor, getLang } from '../lib/i18n.js'
|
||||
import { bwSheet, goalSheet, calendarSheet, workoutDetailSheet, WorkoutRow, bwDeltaColor } from '../sheets.jsx'
|
||||
import LineChart from '../components/LineChart.jsx'
|
||||
import Heatmap from '../components/Heatmap.jsx'
|
||||
@@ -102,6 +102,7 @@ function MuscleBalance({ S }) {
|
||||
const [hard, setHard] = useState(false)
|
||||
const [sel, setSel] = useState(null)
|
||||
const now = useNow()
|
||||
const lang = getLang()
|
||||
const workouts = S.workouts
|
||||
// The user's own last registered bodyweight drives bodyweight-exercise tonnage.
|
||||
const bodyweightKg = useMemo(() => {
|
||||
@@ -113,7 +114,7 @@ function MuscleBalance({ S }) {
|
||||
}, [S.bodyweight, S.unit])
|
||||
const fatigue = useMemo(() => fatigueOf(workouts, now, { bodyweightKg, unit: S.unit }), [workouts, now, bodyweightKg, S.unit])
|
||||
const strength = useMemo(() => strengthOf(workouts, now, { bodyweightKg, unit: S.unit }), [workouts, now, bodyweightKg, S.unit])
|
||||
const muscleExercises = useMemo(() => (sel ? strengthExerciseRowsForMuscle(S, now, sel) : []), [S, now, sel])
|
||||
const muscleExercises = useMemo(() => (sel ? strengthExerciseRowsForMuscle(S, now, sel) : []), [S, now, sel, lang])
|
||||
const lastTrained = useMemo(() => latestMuscleTraining(workouts), [workouts])
|
||||
const strengthHint = slug => {
|
||||
if (lastTrained[slug] == null) return t('not trained')
|
||||
@@ -290,7 +291,7 @@ export default function Stats() {
|
||||
const workouts = S.workouts
|
||||
const monthW = workouts.filter(w => String(w.d || '').slice(0, 7) === todayISO().slice(0, 7)).length
|
||||
|
||||
const nameOf = id => EXIDX[id]?.n || workouts.flatMap(w => w.entries).find(e => e.id === id)?.n || id
|
||||
const nameOf = id => EXIDX[id] ? exerciseNameFor(EXIDX[id]) : (workouts.flatMap(w => w.entries).find(e => e.id === id)?.n || id)
|
||||
const currentOf = id => {
|
||||
for (let i = workouts.length - 1; i >= 0; i--) {
|
||||
const en = workouts[i].entries.find(e => e.id === id)
|
||||
|
||||
@@ -6,7 +6,7 @@ import { exOr } from '../lib/exercises.js'
|
||||
import { effectiveRoutine, lastEntryFor, bestWeightFor, buildSets, freestyleConfig, defaultConfig, setsDoneActive, supersetUnits, unitOf, setLabel, modeOf, isBw, isPerSide, sideReps, repStep, EFFORT, effortOf, stepEffort, capEffort, cascadeWeight, insertWarmupRow, removeRowAt, pairAdjacent, unpairSuperset, cleanupSg } from '../lib/history.js'
|
||||
import { fmtNum, fmtDate, todayISO, exCount, DAYN } from '../lib/format.js'
|
||||
import { beep, vibrate } from '../lib/sound.js'
|
||||
import { t } from '../lib/i18n.js'
|
||||
import { t, exerciseNameFor } from '../lib/i18n.js'
|
||||
import { api } from '../lib/api.js'
|
||||
import { setProgressHighWater, supersetFlowStep } from '../lib/supersetFlow.js'
|
||||
import Media from '../components/Media.jsx'
|
||||
@@ -113,7 +113,7 @@ function ExerciseBlock({ entryIdx, compact, onToggle, onField, onAddSet, onRemov
|
||||
return <>
|
||||
<Media ex={ex} key={entry.id} compact={compact} minimizable />
|
||||
<div className="row between" style={{ marginBottom: 6 }}>
|
||||
<div style={{ fontSize: compact ? 17 : 20, fontWeight: 600, letterSpacing: '-.02em', textTransform: 'capitalize', lineHeight: 1.2 }}>{ex.n}</div>
|
||||
<div style={{ fontSize: compact ? 17 : 20, fontWeight: 600, letterSpacing: '-.02em', textTransform: 'capitalize', lineHeight: 1.2 }}>{exerciseNameFor(ex)}</div>
|
||||
<button className="iconbtn" aria-label={t('Details')} onClick={() => exerciseDetailSheet(ex)}><Icon name="info" /></button>
|
||||
</div>
|
||||
{!compact && (onPairPrev || onPairNext) && <div className="row" style={{ gap: 6, flexWrap: 'wrap', marginBottom: 8 }}>
|
||||
@@ -258,7 +258,7 @@ function ActiveWorkout() {
|
||||
if (!e) return
|
||||
const hasDone = (e.sets || []).some(s => s.done)
|
||||
confirmSheet({
|
||||
title: t('Remove {0}?', exOr(e.id).n),
|
||||
title: t('Remove {0}?', exerciseNameFor(exOr(e.id))),
|
||||
message: hasDone
|
||||
? t('The sets you logged for this exercise in this session will be lost.')
|
||||
: t('This removes the exercise from your current session.'),
|
||||
@@ -273,7 +273,7 @@ function ActiveWorkout() {
|
||||
<div className="muted small" style={{ marginBottom: 12 }}>{t('Which exercise in this superset do you want to remove?')}</div>
|
||||
<div className="list">
|
||||
{unit.map(idx => <div key={idx} className="item" onClick={() => { close(); confirmRemoveExercise(idx) }}>
|
||||
<div className="grow"><div className="tt">{exOr(A.entries[idx]?.id).n}</div></div>
|
||||
<div className="grow"><div className="tt">{exerciseNameFor(exOr(A.entries[idx]?.id))}</div></div>
|
||||
<Icon name="chevronRight" />
|
||||
</div>)}
|
||||
</div>
|
||||
@@ -288,7 +288,7 @@ function ActiveWorkout() {
|
||||
// behave exactly as they do for a reps set.
|
||||
const startTimed = (idx, i) => {
|
||||
const e = A.entries[idx]
|
||||
useUI.getState().startWork(e.sets[i].sec || 45, exOr(e.id).n, elapsed => {
|
||||
useUI.getState().startWork(e.sets[i].sec || 45, exerciseNameFor(exOr(e.id)), elapsed => {
|
||||
mutEntry(idx, en => { en.sets[i].sec = elapsed })
|
||||
if (!useStore.getState().S.active.entries[idx].sets[i].done) toggle(idx, i)
|
||||
})
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
#!/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', 'pt-BR.json')
|
||||
const outputPath = join(root, 'frontend', 'src', 'exercise-names', 'pt-BR.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 pt-BR 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-pt-br-exercise-names.mjs — edit scripts/exercise-name-sources/pt-BR.json\nexport default ' + JSON.stringify(ordered) + '\n')
|
||||
console.log(`Generated ${EXDB.length}/${EXDB.length} pt-BR exercise names.`)
|
||||
@@ -0,0 +1,23 @@
|
||||
# Brazilian Portuguese exercise names
|
||||
|
||||
`pt-BR.json` is the editable source for the Brazilian Portuguese exercise-name
|
||||
pack. It maps every built-in EXDB exercise ID to a Portuguese title. The app
|
||||
combines that title with the unchanged English source at runtime:
|
||||
|
||||
```text
|
||||
Elevação assistida das pernas deitada (assisted lying leg raise)
|
||||
```
|
||||
|
||||
Custom exercise names are never translated. IDs, plan data, workout history,
|
||||
imports and exports continue to use the canonical catalogue entries.
|
||||
|
||||
Generate the runtime pack with:
|
||||
|
||||
```sh
|
||||
node scripts/build-pt-br-exercise-names.mjs
|
||||
```
|
||||
|
||||
The initial translations were produced from the English EXDB titles with LLM
|
||||
assistance and must not be described as reviewed by a native speaker unless a
|
||||
named human reviewer completes that review. They are original translations and
|
||||
were not copied from another Portuguese exercise dataset.
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,87 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { spawnSync } from 'node:child_process'
|
||||
import { 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', 'pt-BR.json')
|
||||
const glossaryPath = join(root, 'scripts', 'instruction-sources', 'GLOSSARY.md')
|
||||
const exercisesPath = join(root, 'frontend', 'src', 'lib', 'exercises-data.js')
|
||||
const claude = process.env.CLAUDE_BIN || 'claude'
|
||||
const option = name => process.argv.find(arg => arg.startsWith(`--${name}=`))?.split('=').slice(1).join('=')
|
||||
const limit = Number(option('limit') || 1324)
|
||||
const batchSize = Number(option('batch-size') || 80)
|
||||
const apply = process.argv.includes('--apply')
|
||||
|
||||
if (!Number.isInteger(limit) || limit < 1 || !Number.isInteger(batchSize) || batchSize < 1) {
|
||||
throw new Error('limit and batch-size must be positive integers')
|
||||
}
|
||||
|
||||
const existing = JSON.parse(readFileSync(sourcePath, 'utf8'))
|
||||
const glossary = readFileSync(glossaryPath, 'utf8')
|
||||
const { EXDB } = await import(pathToFileURL(exercisesPath))
|
||||
const pending = EXDB.filter(exercise => !existing[exercise.id]).slice(0, limit)
|
||||
const next = { ...existing }
|
||||
|
||||
for (let start = 0; start < pending.length; start += batchSize) {
|
||||
const batch = pending.slice(start, start + batchSize)
|
||||
const schema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
translations: {
|
||||
type: 'array', minItems: batch.length, maxItems: batch.length,
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: { id: { type: 'string' }, name: { type: 'string', minLength: 1 } },
|
||||
required: ['id', 'name'], additionalProperties: false
|
||||
}
|
||||
}
|
||||
},
|
||||
required: ['translations'], additionalProperties: false
|
||||
}
|
||||
const input = batch.map(({ id, n, bp, eq, tg }) => ({ id, english: n, bodyPart: bp, equipment: eq, target: tg }))
|
||||
const prompt = `Translate every exercise title below into concise, natural Brazilian Portuguese for a gym app.
|
||||
|
||||
Rules:
|
||||
- Return only the structured JSON required by the schema, with every ID exactly once and in input order.
|
||||
- Return only the Portuguese title in "name". Do not append or repeat the English title.
|
||||
- Preserve exercise identity, equipment, stance, grip, direction, side, assisted/weighted status and version qualifiers.
|
||||
- Prefer established Brazilian gym terminology (for example: supino, agachamento, remada, puxada, rosca, elevação, extensão, flexão de braços, barra fixa, afundo, levantamento terra).
|
||||
- Keep accepted equipment or exercise names such as kettlebell, Smith, hack squat, leg press and Romanian deadlift when that is the clearest Brazilian usage.
|
||||
- Use sentence case, not Title Case. Do not use Portuguese (Portugal) terms.
|
||||
- Do not repair or reinterpret questionable source mechanics; translate the title faithfully.
|
||||
- Use the metadata only to disambiguate the English title.
|
||||
|
||||
GLOSSARY:
|
||||
${glossary}
|
||||
|
||||
INPUT:
|
||||
${JSON.stringify(input)}`
|
||||
|
||||
console.log(`Translating names ${start + 1}-${start + batch.length} of ${pending.length} (${batch[0].id}…${batch.at(-1).id})`)
|
||||
const result = spawnSync(claude, [
|
||||
'-p', '--model', 'sonnet', '--effort', 'high', '--no-session-persistence',
|
||||
'--permission-mode', 'dontAsk', '--disallowedTools', 'Bash', 'Edit', 'Write', 'Read',
|
||||
'--output-format', 'json', '--max-budget-usd', '2', '--json-schema', JSON.stringify(schema)
|
||||
], { input: prompt, encoding: 'utf8', maxBuffer: 16 * 1024 * 1024 })
|
||||
if (result.status !== 0) throw new Error(result.stderr || result.stdout || `Claude exited ${result.status}`)
|
||||
const envelope = JSON.parse(result.stdout)
|
||||
if (envelope.is_error || !envelope.structured_output) throw new Error(envelope.result || 'Claude returned no structured output')
|
||||
const rows = envelope.structured_output.translations
|
||||
const received = new Map(rows.map(row => [row.id, row.name.trim()]))
|
||||
if (received.size !== batch.length) throw new Error('Claude returned duplicate or missing IDs')
|
||||
for (const exercise of batch) {
|
||||
const name = received.get(exercise.id)
|
||||
if (!name) throw new Error(`${exercise.id}: missing translated name`)
|
||||
next[exercise.id] = name
|
||||
}
|
||||
if (apply) {
|
||||
writeFileSync(sourcePath, JSON.stringify(next, null, 2) + '\n')
|
||||
console.log(`Checkpoint: ${Object.keys(next).length}/${EXDB.length} names`)
|
||||
}
|
||||
}
|
||||
|
||||
if (!apply) console.log(`Validated ${pending.length} names. Re-run with --apply to update the source.`)
|
||||
else console.log(`Updated ${sourcePath}: ${Object.keys(next).length}/${EXDB.length} names`)
|
||||
+2
-1
@@ -185,7 +185,8 @@ docker compose up -d</code></pre>
|
||||
<h3>Where does the exercise database come from?</h3>
|
||||
<p>From <a href="https://github.com/hasaneyldrm/exercises-dataset" rel="noopener">hasaneyldrm/exercises-dataset</a>:
|
||||
1,324 exercises with animations and instructions in 11 languages, including openGym's
|
||||
separately curated Brazilian Portuguese translation. That dataset licenses the two
|
||||
separately curated Brazilian Portuguese translation. In pt-BR, built-in exercise names
|
||||
show Portuguese first and the canonical English title in parentheses. That dataset licenses the two
|
||||
halves differently, and so does openGym: the exercise metadata and instruction text are
|
||||
<b>MIT</b>, while the images and animations are
|
||||
<b>© <a href="https://gymvisual.com/" rel="noopener">Gym visual</a></b>, used under the
|
||||
|
||||
+1
-1
@@ -112,7 +112,7 @@
|
||||
<div class="feat"><div class="ic">🎯</div><h3>Effort per set</h3><p>Rate a set as RIR or RPE — whichever scale you already think in. Optional, and every set keeps the scale it was logged with.</p></div>
|
||||
<div class="feat"><div class="ic">☀️</div><h3>Screen stays awake</h3><p>No unlocking the phone between sets. The screen stays lit while a workout runs, and lets go the moment you finish.</p></div>
|
||||
<div class="feat"><div class="ic">📥</div><h3>Bring your history</h3><p>Import from FitNotes, Strong, Hevy — including the RPE they recorded — or body weight straight out of an Apple Health export.</p></div>
|
||||
<div class="feat"><div class="ic">🌍</div><h3>13 languages</h3><p>Full UI translation, exercise instructions in 11 languages, loaded on demand.</p></div>
|
||||
<div class="feat"><div class="ic">🌍</div><h3>13 languages</h3><p>Full UI translation, exercise instructions in 11 languages, and bilingual PT-BR exercise names, loaded on demand.</p></div>
|
||||
<div class="feat"><div class="ic">🔑</div><h3>Passkeys, not passwords</h3><p>Self-hosted profiles sign in with Face ID / fingerprint. Each person's data stays their own.</p></div>
|
||||
<div class="feat"><div class="ic">🎨</div><h3>Designed, not assembled</h3><p>Light & dark themes, 8 accent colors, a hand-drawn icon set. Looks the same on every phone.</p></div>
|
||||
<div class="feat"><div class="ic">🔥</div><h3>Warm-up sets</h3><p>Mark the ramp-up rows as warm-ups and they stay out of your 1RM, your progression and the fatigue map — present in the session, absent from the numbers.</p></div>
|
||||
|
||||
Reference in new issue
Block a user