diff --git a/frontend/src/lib/format.js b/frontend/src/lib/format.js index 374d540..3817119 100644 --- a/frontend/src/lib/format.js +++ b/frontend/src/lib/format.js @@ -36,6 +36,7 @@ export const fmtNum = n => (Math.round(n * 10) / 10).toLocaleString(dateLocale() export const fmtVol = (v, unit) => fmtNum(v) + ' ' + unit // Plural forms are not automatic when the English string is the key. export const exCount = n => t(n === 1 ? '{0} exercise' : '{0} exercises', n) +export const routineCount = n => t(n === 1 ? '{0} routine' : '{0} routines', n) /* ---------------------------------------------------------------- week start -- Where a week begins is a local convention, not a fact: most of Europe starts on diff --git a/frontend/src/lib/pt-br-locale.test.js b/frontend/src/lib/pt-br-locale.test.js index f692c60..42c163a 100644 --- a/frontend/src/lib/pt-br-locale.test.js +++ b/frontend/src/lib/pt-br-locale.test.js @@ -27,7 +27,7 @@ describe('Brazilian Portuguese locale', () => { .sort(byCodeUnit) const fingerprint = createHash('sha256').update(JSON.stringify(inherited)).digest('hex') - expect(Object.keys(PT_BR_OVERRIDES)).toHaveLength(644) + expect(Object.keys(PT_BR_OVERRIDES)).toHaveLength(645) expect(inherited).toHaveLength(647) // If this fails, review the changed keys and wording before accepting a new hash. From // frontend/: node scripts/pt-br-inheritance-fingerprint.mjs --list diff --git a/frontend/src/locales/de.js b/frontend/src/locales/de.js index fad9cba..c54dff9 100644 --- a/frontend/src/locales/de.js +++ b/frontend/src/locales/de.js @@ -580,6 +580,7 @@ export default { '{0} exercises in the file aren’t in your library and were left out.': '{0} Übungen aus der Datei sind nicht in deiner Bibliothek und wurden weggelassen.', 'Use this weekly schedule': 'Diesen Wochenplan verwenden', 'Replaces your current Mon–Sun assignments.': 'Ersetzt deine aktuelle Mo–So-Belegung.', + 'Added {0} routine to your plan': '{0} Routine zu deinem Plan hinzugefügt', 'Added {0} routines to your plan': '{0} Routinen zu deinem Plan hinzugefügt', 'this isn’t an openGym plan file': 'das ist keine openGym-Plandatei', 'Shared routine': 'Geteilte Routine', diff --git a/frontend/src/locales/es.js b/frontend/src/locales/es.js index 68e2144..b77e136 100644 --- a/frontend/src/locales/es.js +++ b/frontend/src/locales/es.js @@ -561,6 +561,7 @@ export default { '{0} exercises in the file aren’t in your library and were left out.': '{0} ejercicios del archivo no están en tu biblioteca y se han omitido.', 'Use this weekly schedule': 'Usar este horario semanal', 'Replaces your current Mon–Sun assignments.': 'Reemplaza tu asignación actual de lun–dom.', + 'Added {0} routine to your plan': 'Se añadió {0} rutina a tu plan', 'Added {0} routines to your plan': 'Se añadieron {0} rutinas a tu plan', 'this isn’t an openGym plan file': 'esto no es un archivo de plan de openGym', 'Shared routine': 'Rutina compartida', diff --git a/frontend/src/locales/fr.js b/frontend/src/locales/fr.js index ff4b17c..5feda70 100644 --- a/frontend/src/locales/fr.js +++ b/frontend/src/locales/fr.js @@ -561,6 +561,7 @@ export default { '{0} exercises in the file aren’t in your library and were left out.': '{0} exercices du fichier ne sont pas dans ta bibliothèque et ont été ignorés.', 'Use this weekly schedule': 'Utiliser ce planning hebdomadaire', 'Replaces your current Mon–Sun assignments.': 'Remplace ton attribution lun–dim actuelle.', + 'Added {0} routine to your plan': '{0} routine ajoutée à ton plan', 'Added {0} routines to your plan': '{0} routines ajoutées à ton plan', 'this isn’t an openGym plan file': 'ce n\'est pas un fichier de plan openGym', 'Shared routine': 'Routine partagée', diff --git a/frontend/src/locales/hi.js b/frontend/src/locales/hi.js index da466b3..485de72 100644 --- a/frontend/src/locales/hi.js +++ b/frontend/src/locales/hi.js @@ -561,6 +561,7 @@ export default { '{0} exercises in the file aren’t in your library and were left out.': 'फ़ाइल के {0} व्यायाम आपकी लाइब्रेरी में नहीं हैं और छोड़ दिए गए।', 'Use this weekly schedule': 'यह साप्ताहिक कार्यक्रम इस्तेमाल करें', 'Replaces your current Mon–Sun assignments.': 'आपके मौजूदा सोम–रवि निर्धारण को बदल देता है।', + 'Added {0} routine to your plan': 'आपके प्लान में {0} रूटीन जोड़ा गया', 'Added {0} routines to your plan': 'आपके प्लान में {0} रूटीन जोड़े गए', 'this isn’t an openGym plan file': 'यह openGym प्लान फ़ाइल नहीं है', 'Shared routine': 'साझा किया गया रूटीन', diff --git a/frontend/src/locales/hu.js b/frontend/src/locales/hu.js index f99fa4f..0cfa720 100644 --- a/frontend/src/locales/hu.js +++ b/frontend/src/locales/hu.js @@ -540,6 +540,7 @@ export default { '{0} exercises in the file aren’t in your library and were left out.': '{0} gyakorlat a fájlban nincs a könyvtáradban, ezért kimaradt.', 'Use this weekly schedule': 'Heti beosztás alkalmazása', 'Replaces your current Mon–Sun assignments.': 'Lecseréli a jelenlegi H–V beosztásod.', + 'Added {0} routine to your plan': '{0} rutin hozzáadva a tervedhez', 'Added {0} routines to your plan': '{0} rutin hozzáadva a tervedhez', 'this isn’t an openGym plan file': 'ez nem egy openGym tervfájl', 'Shared routine': 'Megosztott rutin', diff --git a/frontend/src/locales/it.js b/frontend/src/locales/it.js index 3c8c841..8e80cd7 100644 --- a/frontend/src/locales/it.js +++ b/frontend/src/locales/it.js @@ -561,6 +561,7 @@ export default { '{0} exercises in the file aren’t in your library and were left out.': '{0} esercizi del file non sono nella tua libreria e sono stati esclusi.', 'Use this weekly schedule': 'Usa questo programma settimanale', 'Replaces your current Mon–Sun assignments.': 'Sostituisce la tua assegnazione lun–dom attuale.', + 'Added {0} routine to your plan': 'Aggiunta {0} routine al tuo piano', 'Added {0} routines to your plan': 'Aggiunte {0} routine al tuo piano', 'this isn’t an openGym plan file': 'questo non è un file di piano openGym', 'Shared routine': 'Routine condivisa', diff --git a/frontend/src/locales/ko.js b/frontend/src/locales/ko.js index 48ea492..d5b13d3 100644 --- a/frontend/src/locales/ko.js +++ b/frontend/src/locales/ko.js @@ -561,6 +561,7 @@ export default { '{0} exercises in the file aren’t in your library and were left out.': '파일의 운동 {0}개가 라이브러리에 없어 제외했습니다.', 'Use this weekly schedule': '이 주간 일정 사용', 'Replaces your current Mon–Sun assignments.': '현재 월–일 배정을 대체합니다.', + 'Added {0} routine to your plan': '계획에 루틴 {0}개를 추가했습니다', 'Added {0} routines to your plan': '계획에 루틴 {0}개를 추가했습니다', 'this isn’t an openGym plan file': 'openGym 계획 파일이 아닙니다', 'Shared routine': '공유된 루틴', diff --git a/frontend/src/locales/pl.js b/frontend/src/locales/pl.js index 213baab..2d3321e 100644 --- a/frontend/src/locales/pl.js +++ b/frontend/src/locales/pl.js @@ -561,6 +561,7 @@ export default { '{0} exercises in the file aren’t in your library and were left out.': '{0} ćwiczeń z pliku nie ma w Twojej bibliotece i zostały pominięte.', 'Use this weekly schedule': 'Użyj tego harmonogramu tygodnia', 'Replaces your current Mon–Sun assignments.': 'Zastępuje Twój obecny przydział pon–niedz.', + 'Added {0} routine to your plan': 'Dodano {0} plan treningowy do Twojego planu', 'Added {0} routines to your plan': 'Dodano {0} planów treningowych do Twojego planu', 'this isn’t an openGym plan file': 'to nie jest plik planu openGym', 'Shared routine': 'Udostępniony plan treningowy', diff --git a/frontend/src/locales/pt-BR.js b/frontend/src/locales/pt-BR.js index 324b0f2..087c696 100644 --- a/frontend/src/locales/pt-BR.js +++ b/frontend/src/locales/pt-BR.js @@ -210,6 +210,7 @@ export const PT_BR_OVERRIDES = { '{0} exercise in the file isn’t in your library and was left out.': '{0} exercício do arquivo não está na sua biblioteca e foi ignorado.', '{0} exercises in the file aren’t in your library and were left out.': '{0} exercícios do arquivo não estão na sua biblioteca e foram ignorados.', 'Replaces your current Mon–Sun assignments.': 'Substitui os dias definidos de segunda a domingo.', + 'Added {0} routine to your plan': '{0} rotina adicionada ao seu plano', 'Added {0} routines to your plan': '{0} rotinas adicionadas ao seu plano', 'this isn’t an openGym plan file': 'este não é um arquivo de plano do openGym', 'This screen could not be drawn. Your data is safe on this device.': 'Não foi possível exibir esta tela. Seus dados estão seguros neste dispositivo.', diff --git a/frontend/src/locales/pt.js b/frontend/src/locales/pt.js index ea44d46..7619b0f 100644 --- a/frontend/src/locales/pt.js +++ b/frontend/src/locales/pt.js @@ -561,6 +561,7 @@ export default { '{0} exercises in the file aren’t in your library and were left out.': '{0} exercícios do ficheiro não estão na tua biblioteca e foram ignorados.', 'Use this weekly schedule': 'Usar este horário semanal', 'Replaces your current Mon–Sun assignments.': 'Substitui a tua atribuição atual de seg–dom.', + 'Added {0} routine to your plan': 'Adicionada {0} rotina ao teu plano', 'Added {0} routines to your plan': 'Adicionadas {0} rotinas ao teu plano', 'this isn’t an openGym plan file': 'isto não é um ficheiro de plano openGym', 'Shared routine': 'Rotina partilhada', diff --git a/frontend/src/locales/ru.js b/frontend/src/locales/ru.js index 46ce8ef..85aaa63 100644 --- a/frontend/src/locales/ru.js +++ b/frontend/src/locales/ru.js @@ -561,6 +561,7 @@ export default { '{0} exercises in the file aren’t in your library and were left out.': '{0} упражнений из файла отсутствуют в вашей библиотеке и были пропущены.', 'Use this weekly schedule': 'Использовать это расписание недели', 'Replaces your current Mon–Sun assignments.': 'Заменяет твоё текущее распределение пн–вс.', + 'Added {0} routine to your plan': 'В твой план добавлена {0} программа', 'Added {0} routines to your plan': 'В твой план добавлено программ: {0}', 'this isn’t an openGym plan file': 'это не файл плана openGym', 'Shared routine': 'Общая программа', diff --git a/frontend/src/locales/th.js b/frontend/src/locales/th.js index f2b372d..bd0c87c 100644 --- a/frontend/src/locales/th.js +++ b/frontend/src/locales/th.js @@ -540,6 +540,7 @@ export default { '{0} exercises in the file aren’t in your library and were left out.': 'มี {0} ท่าในไฟล์ที่ไม่มีในคลังของคุณ จึงถูกข้ามไป', 'Use this weekly schedule': 'ใช้ตารางรายสัปดาห์นี้', 'Replaces your current Mon–Sun assignments.': 'จะแทนที่ตารางจันทร์–อาทิตย์ปัจจุบันของคุณ', + 'Added {0} routine to your plan': 'เพิ่ม {0} รูทีนเข้าแผนของคุณแล้ว', 'Added {0} routines to your plan': 'เพิ่ม {0} รูทีนเข้าแผนของคุณแล้ว', 'this isn’t an openGym plan file': 'นี่ไม่ใช่ไฟล์แผนของ openGym', 'Shared routine': 'รูทีนที่แชร์มา', diff --git a/frontend/src/locales/tr.js b/frontend/src/locales/tr.js index 95720d1..4bad8ce 100644 --- a/frontend/src/locales/tr.js +++ b/frontend/src/locales/tr.js @@ -561,6 +561,7 @@ export default { '{0} exercises in the file aren’t in your library and were left out.': 'Dosyadaki {0} egzersiz kitaplığında yok ve atlandı.', 'Use this weekly schedule': 'Bu hafta programını kullan', 'Replaces your current Mon–Sun assignments.': 'Mevcut Pzt–Paz atamanı değiştirir.', + 'Added {0} routine to your plan': 'Planına {0} rutin eklendi', 'Added {0} routines to your plan': 'Planına {0} rutin eklendi', 'this isn’t an openGym plan file': 'bu bir openGym plan dosyası değil', 'Shared routine': 'Paylaşılan rutin', diff --git a/frontend/src/locales/zh.js b/frontend/src/locales/zh.js index f45110e..96f33b9 100644 --- a/frontend/src/locales/zh.js +++ b/frontend/src/locales/zh.js @@ -561,6 +561,7 @@ export default { '{0} exercises in the file aren’t in your library and were left out.': '文件中有 {0} 个动作不在你的动作库中,已略过。', 'Use this weekly schedule': '使用此每周日程', 'Replaces your current Mon–Sun assignments.': '替换你当前的周一至周日安排。', + 'Added {0} routine to your plan': '已向你的计划添加 {0} 个训练日', 'Added {0} routines to your plan': '已向你的计划添加 {0} 个训练日', 'this isn’t an openGym plan file': '这不是 openGym 计划文件', 'Shared routine': '共享的训练日', diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsx index 019bd88..9221d2f 100644 --- a/frontend/src/sheets.jsx +++ b/frontend/src/sheets.jsx @@ -3,7 +3,7 @@ import { useStore } from './store/useStore.js' import { useUI } from './store/useUI.js' import { EXDB, EXIDX, BODYPARTS, isCardio, isBodyweightEq, allExercises, equipmentOf, smOf, matchExercise, exOr } from './lib/exercises.js' import { activeProfile, exAvailable, ALL_EQUIPMENT, newProfile } from './lib/equipment.js' -import { fmtDate, fmtNum, capWords, fmtVol, fmtDur, durPart, todayISO, isoOf, uid, exCount, DAYN, DAYS, weekOrder, weekStartOf, weekDayOffset, MONTHS_LONG, ACCENTS } from './lib/format.js' +import { fmtDate, fmtNum, capWords, fmtVol, fmtDur, durPart, todayISO, isoOf, uid, exCount, routineCount, DAYN, DAYS, weekOrder, weekStartOf, weekDayOffset, MONTHS_LONG, ACCENTS } from './lib/format.js' import { lastEntryFor, bestWeightFor, bestWeightForEntry, buildSets, effectiveRoutineIds, workoutVolume, setsDone, setsDoneActive, setUnitsTotal, lastBW, supersetUnits, unitOf, setLabel, defaultConfig, cleanupSg, modeOf, effortOf, EFFORT, capEffort, stepEffort, isBw, isPerSide, sideReps, workSetsDone, applyIntensifierPlan, MAX_PLANNED_WARMUPS, NOTE_MAX } from './lib/history.js' import { usesBar, barWeightFor, defaultBarWeight, hasBarOverride } from './lib/bar.js' import { toScale, rirOf, EFFORT_PRESETS, effortColor } from './lib/effort.js' @@ -1517,13 +1517,13 @@ function PlanImport({ bundle, close }) { const apply = () => { update(s => mergePlan(s, bundle, { schedule })) close() - toast(t('Added {0} routines to your plan', bundle.routineCount)) + toast(t(bundle.routineCount === 1 ? 'Added {0} routine to your plan' : 'Added {0} routines to your plan', bundle.routineCount)) nav('/plan') } return <>

{bundle.name ? t('Import “{0}”', bundle.name) : t('Import this plan')}

- {t(bundle.routineCount === 1 ? '{0} routine' : '{0} routines', bundle.routineCount)} + {routineCount(bundle.routineCount)} {' · ' + exCount(bundle.exerciseCount)} {bundle.scheduledDays > 0 ? ' · ' + t(bundle.scheduledDays === 1 ? 'scheduled on {0} day' : 'scheduled on {0} days', bundle.scheduledDays) diff --git a/frontend/src/sheets.plan-import-toast.test.jsx b/frontend/src/sheets.plan-import-toast.test.jsx new file mode 100644 index 0000000..27915fd --- /dev/null +++ b/frontend/src/sheets.plan-import-toast.test.jsx @@ -0,0 +1,56 @@ +// @vitest-environment happy-dom +// Importing a one-routine plan file toasted "Added 1 routines to your plan" (QA copy): the +// sheet's summary line already picked the singular, the toast after the merge did not. +import React, { act } from 'react' +import { afterEach, beforeEach, describe, expect, it } from 'vitest' +import { createRoot } from 'react-dom/client' +import { useStore } from './store/useStore.js' +import { useUI } from './store/useUI.js' +import { planImportSheet } from './sheets.jsx' +import { parsePlan } from './lib/plan-share.js' +import { EXDB } from './lib/exercises.js' + +const clone = v => JSON.parse(JSON.stringify(v)) +const ids = EXDB.filter(e => e.bp !== 'cardio').slice(0, 2).map(e => e.id) +const mounted = [] + +function renderTop() { + const sheet = useUI.getState().sheets.at(-1) + const host = document.createElement('div') + document.body.appendChild(host) + const root = createRoot(host) + mounted.push(root) + act(() => root.render(sheet.render(() => useUI.getState().closeSheet(sheet.id)))) + return host +} +const buttonFor = (host, label) => [...host.querySelectorAll('button')].find(b => b.textContent === label) +const bundleOf = routines => parsePlan({ opengym_plan: 1, unit: 'kg', week: {}, routines, customEx: [] }, 'kg') +const routine = (id, name) => ({ id, name, emoji: null, ex: [{ id: ids[0], sets: 3, reps: 8, weight: 40 }] }) + +beforeEach(() => { + globalThis.IS_REACT_ACT_ENVIRONMENT = true + useUI.setState({ sheets: [], toastMsg: '' }) + document.body.innerHTML = '' + const S = clone(useStore.getState().S) + S.routines = [] + S.week = {} + useStore.setState({ S, user: null }) +}) +afterEach(() => { act(() => { mounted.splice(0).forEach(r => r.unmount()) }) }) + +describe('Plan import sheet — the toast counts what it added', () => { + it('says "1 routine" for a single routine', () => { + planImportSheet(bundleOf([routine('a', 'Push')])) + const host = renderTop() + act(() => { buttonFor(host, 'Add to my plan').click() }) + expect(useStore.getState().S.routines).toHaveLength(1) + expect(useUI.getState().toastMsg).toBe('Added 1 routine to your plan') + }) + + it('keeps the plural for several', () => { + planImportSheet(bundleOf([routine('a', 'Push'), routine('b', 'Pull')])) + const host = renderTop() + act(() => { buttonFor(host, 'Add to my plan').click() }) + expect(useUI.getState().toastMsg).toBe('Added 2 routines to your plan') + }) +}) diff --git a/frontend/src/views/Plan.jsx b/frontend/src/views/Plan.jsx index bd933e3..bacca3c 100644 --- a/frontend/src/views/Plan.jsx +++ b/frontend/src/views/Plan.jsx @@ -1,6 +1,6 @@ import { useNavigate } from 'react-router-dom' import { useStore } from '../store/useStore.js' -import { DAYN, weekOrder, weekStartOf, uid, exCount } from '../lib/format.js' +import { DAYN, weekOrder, weekStartOf, uid, exCount, routineCount } from '../lib/format.js' import { t } from '../lib/i18n.js' import { dayAssignSheet, dayAddRoutineSheet, starterPlanSheet, planToolsSheet } from '../sheets.jsx' import Icon from '../components/Icon.jsx' @@ -65,7 +65,7 @@ export default function Plan() { return
{t(DAYN[d])}
-
{t('{0} routines', dayRoutines.length)}
+
{routineCount(dayRoutines.length)}
{dayRoutines.map(r =>
diff --git a/frontend/src/views/Plan.routine-count.test.jsx b/frontend/src/views/Plan.routine-count.test.jsx new file mode 100644 index 0000000..1c00ed5 --- /dev/null +++ b/frontend/src/views/Plan.routine-count.test.jsx @@ -0,0 +1,60 @@ +// @vitest-environment happy-dom +// A weekday with one routine read "1 routines" (QA copy): the header formatted the count +// with the plural key only, although both forms have been in every pack for a long time. +import React, { act } from 'react' +import { createRoot } from 'react-dom/client' +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import Plan from './Plan.jsx' + +globalThis.IS_REACT_ACT_ENVIRONMENT = true + +const mocks = vi.hoisted(() => { + const state = { S: null } + state.snapshot = () => ({ + S: state.S, + user: null, + update: mut => { + const next = structuredClone(state.S) + mut(next) + state.S = next + }, + }) + return state +}) +vi.mock('../store/useStore.js', () => { + const useStore = selector => (selector ? selector(mocks.snapshot()) : mocks.snapshot()) + useStore.getState = mocks.snapshot + return { useStore, DEF: { reminder: { time: '17:30' } }, hasData: () => false } +}) +vi.mock('react-router-dom', () => ({ useNavigate: () => () => {} })) +vi.mock('../lib/mobile.js', () => ({ MOBILE: false, isAndroid: () => Promise.resolve(false), shareExport: vi.fn(), syncReminder: vi.fn() })) +vi.mock('../sheets.jsx', () => ({ + starterPlanSheet: vi.fn(), dayAssignSheet: vi.fn(), dayAddRoutineSheet: vi.fn(), planToolsSheet: vi.fn(), +})) + +let host, root +beforeEach(() => { + mocks.S = { + unit: 'kg', workouts: [], exWeights: {}, week: {}, dayPlan: {}, + routines: [{ id: 'r1', name: 'Push', emoji: null, ex: [] }, { id: 'r2', name: 'Pull', emoji: null, ex: [] }], + } + host = document.createElement('div') + document.body.appendChild(host) + root = createRoot(host) +}) +afterEach(() => { + act(() => root.unmount()) + host.remove() +}) + +const mount = () => act(() => root.render()) +const countOn = day => [...host.querySelectorAll('.item')].find(el => el.querySelector('.tt')?.textContent === day)?.querySelector('.small.dim')?.textContent + +describe('Plan — the day header counts its routines', () => { + it('uses the singular for one routine and the plural for more', () => { + mocks.S.week = { 1: ['r1'], 2: ['r1', 'r2'] } + mount() + expect(countOn('Monday')).toBe('1 routine') + expect(countOn('Tuesday')).toBe('2 routines') + }) +})