Localization: 12 UI languages + exercise instructions in 10 (#7)
Adds a Language setting (Settings → Appearance) that translates the whole app: a tiny dependency-free i18n layer (English source strings as keys, per-language dictionaries in frontend/src/locales/) plus per-language exercise-instruction packs generated from the upstream dataset (frontend/src/instr/, via scripts/build-instructions.mjs). UI: en, de, es, fr, it, pt, pl, tr, ru, zh, ko, hi. Instructions: all of those except de/pt (not in the upstream dataset — fall back to English). Body-part/equipment/muscle labels and date formats are localized too; exercise names stay English (upstream limitation). Everything is lazy-loaded per language (Vite code-splitting), so the initial bundle is unchanged; the choice syncs with the profile like the theme. Closes #7.
This commit is contained in:
1 parent
b9f8d18bbd
commit
c05b0756ec
44 files changed
+3891
-274
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import { useEffect, useRef } from 'react'
|
||||
import { fmtVol, isoOf, todayISO } from '../lib/format.js'
|
||||
import { fmtVol, isoOf, todayISO, MONTHS } from '../lib/format.js'
|
||||
import { t } from '../lib/i18n.js'
|
||||
|
||||
// GitHub-style activity heatmap, shaded by time trained per day.
|
||||
export default function Heatmap({ S, onDay }) {
|
||||
@@ -27,7 +28,7 @@ export default function Heatmap({ S, onDay }) {
|
||||
const colStart = new Date(start); colStart.setDate(start.getDate() + wk * 7)
|
||||
const mo = colStart.getMonth()
|
||||
const showM = mo !== lastMonth && colStart.getDate() <= 7 && wk < 51
|
||||
months.push(<span key={wk}>{showM ? ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][mo] : ''}</span>)
|
||||
months.push(<span key={wk}>{showM ? t(MONTHS[mo]) : ''}</span>)
|
||||
if (colStart.getDate() <= 7) lastMonth = mo
|
||||
const cells = []
|
||||
for (let d = 0; d < 7; d++) {
|
||||
@@ -36,7 +37,7 @@ export default function Heatmap({ S, onDay }) {
|
||||
const a = agg[key]
|
||||
const cls = 'hm-c l' + level(a) + (key === todayISO() ? ' today' : '') + (day > today ? ' future' : '')
|
||||
cells.push(<div key={d} className={cls}
|
||||
title={key + (a ? ` · ${a.n} workout${a.n > 1 ? 's' : ''} · ${a.min} min · ${fmtVol(a.vol, S.unit)}` : '')}
|
||||
title={key + (a ? ` · ${t(a.n === 1 ? '{0} workout' : '{0} workouts', a.n)} · ${a.min} min · ${fmtVol(a.vol, S.unit)}` : '')}
|
||||
onClick={a ? () => onDay(key) : undefined} />)
|
||||
}
|
||||
cols.push(<div key={wk} className="hm-col">{cells}</div>)
|
||||
@@ -46,10 +47,10 @@ export default function Heatmap({ S, onDay }) {
|
||||
<div className="hm-wrap" ref={wrapRef}>
|
||||
<div className="hm-months" style={{ marginLeft: 30 }}>{months}</div>
|
||||
<div className="hm-body">
|
||||
<div className="hm-days"><span>Mon</span><span /><span>Wed</span><span /><span>Fri</span><span /><span /></div>
|
||||
<div className="hm-days"><span>{t('Mon')}</span><span /><span>{t('Wed')}</span><span /><span>{t('Fri')}</span><span /><span /></div>
|
||||
<div className="hm-grid">{cols}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="hm-legend">Less time <div className="hm-c l0" /><div className="hm-c l1" /><div className="hm-c l2" /><div className="hm-c l3" /><div className="hm-c l4" /> More time</div>
|
||||
<div className="hm-legend">{t('Less time')} <div className="hm-c l0" /><div className="hm-c l1" /><div className="hm-c l2" /><div className="hm-c l3" /><div className="hm-c l4" /> {t('More time')}</div>
|
||||
</>
|
||||
}
|
||||
@@ -1,12 +1,13 @@
|
||||
import { useRef, useState } from 'react'
|
||||
import { fmtNum, fmtDate, MONTHS, isoOf } from '../lib/format.js'
|
||||
import { t } from '../lib/i18n.js'
|
||||
|
||||
// points: [{ t: ms, y: num, d?: iso }] sorted by t. opts: { h, unit, color, axes, goal }
|
||||
export default function LineChart({ points, h = 150, unit = '', color = 'var(--acc)', axes = true, goal = null }) {
|
||||
const svgRef = useRef(null)
|
||||
const [hover, setHover] = useState(null) // { x, y, iso, v }
|
||||
|
||||
if (!points || points.length === 0) return <div className="empty small">No data yet</div>
|
||||
if (!points || points.length === 0) return <div className="empty small">{t('No data yet')}</div>
|
||||
const W = 340, H = h
|
||||
const P = { l: axes ? 34 : 8, r: 12, t: 10, b: axes ? 22 : 8 }
|
||||
const single = points.length === 1
|
||||
@@ -36,11 +37,11 @@ export default function LineChart({ points, h = 150, unit = '', color = 'var(--a
|
||||
const d0 = new Date(t0), d1 = new Date(t1)
|
||||
const ticks = []
|
||||
let m = new Date(d0.getFullYear(), d0.getMonth() + 1, 1)
|
||||
while (m <= d1) { ticks.push({ t: +m, txt: MONTHS[m.getMonth()] }); m = new Date(m.getFullYear(), m.getMonth() + 1, 1) }
|
||||
while (m <= d1) { ticks.push({ t: +m, txt: t(MONTHS[m.getMonth()]) }); m = new Date(m.getFullYear(), m.getMonth() + 1, 1) }
|
||||
if (ticks.length === 0 && !single) {
|
||||
for (let i = 0; i <= 2; i++) {
|
||||
const t = t0 + (t1 - t0) * i / 2, dd = new Date(t)
|
||||
ticks.push({ t, txt: dd.getDate() + ' ' + MONTHS[dd.getMonth()], anchor: i === 0 ? 'start' : i === 2 ? 'end' : 'middle' })
|
||||
const tv = t0 + (t1 - t0) * i / 2, dd = new Date(tv)
|
||||
ticks.push({ t: tv, txt: dd.getDate() + ' ' + t(MONTHS[dd.getMonth()]), anchor: i === 0 ? 'start' : i === 2 ? 'end' : 'middle' })
|
||||
}
|
||||
}
|
||||
const every = Math.max(1, Math.ceil(ticks.length / 7))
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useState } from 'react'
|
||||
import { imgSrc, gifSrc } from '../lib/exercises.js'
|
||||
import { t } from '../lib/i18n.js'
|
||||
|
||||
// Big autoplaying animation; tap toggles to the still frame. `compact` shrinks it (superset cards).
|
||||
export default function Media({ ex, id, compact }) {
|
||||
@@ -7,7 +8,7 @@ export default function Media({ ex, id, compact }) {
|
||||
return (
|
||||
<div className={'exmedia' + (compact ? ' compact' : '')} id={id} onClick={() => setPlaying(p => !p)}>
|
||||
<img decoding="async" src={playing ? gifSrc(ex) : imgSrc(ex)} alt={ex.n} />
|
||||
<span className="gifhint">{playing ? '⏸ tap to pause' : '▶ tap to play'}</span>
|
||||
<span className="gifhint">{playing ? '⏸ ' + t('tap to pause') : '▶ ' + t('tap to play')}</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { useUI } from '../store/useUI.js'
|
||||
import { t } from '../lib/i18n.js'
|
||||
export default function RestTimer() {
|
||||
const timer = useUI(s => s.timer)
|
||||
const { addRest, stopRest } = useUI()
|
||||
@@ -10,7 +11,7 @@ export default function RestTimer() {
|
||||
<div className="t">{m}:{s}</div>
|
||||
<div className="bar"><i style={{ width: pct + '%' }} /></div>
|
||||
<button className="btn sm" onClick={() => addRest(15)}>+15s</button>
|
||||
<button className="btn sm primary" onClick={stopRest}>Skip</button>
|
||||
<button className="btn sm primary" onClick={stopRest}>{t('Skip')}</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import { useLocation, useNavigate } from 'react-router-dom'
|
||||
import { useStore } from '../store/useStore.js'
|
||||
import { effectiveRoutine } from '../lib/history.js'
|
||||
import { todayISO } from '../lib/format.js'
|
||||
import { t } from '../lib/i18n.js'
|
||||
|
||||
const ICONS = {
|
||||
home: <path d="M3 10.5 12 3l9 7.5M5 9.5V21h14V9.5" />,
|
||||
@@ -31,14 +32,14 @@ export default function TabBar({ onStart }) {
|
||||
|
||||
return (
|
||||
<nav id="tabbar">
|
||||
<button className={on('home') ? 'on' : ''} onClick={() => nav('/home')}><Icon k="home" /><span>Home</span></button>
|
||||
<button className={on('plan') ? 'on' : ''} onClick={() => nav('/plan')}><Icon k="plan" /><span>Plan</span></button>
|
||||
<button className={on('home') ? 'on' : ''} onClick={() => nav('/home')}><Icon k="home" /><span>{t('Home')}</span></button>
|
||||
<button className={on('plan') ? 'on' : ''} onClick={() => nav('/plan')}><Icon k="plan" /><span>{t('Plan')}</span></button>
|
||||
<button className={'start' + (S.active ? ' rec' : '')} onClick={startWorkout}>
|
||||
<span className="cir"><svg viewBox="0 0 24 24"><path d="M6.5 6.5v11M17.5 6.5v11M2.5 9.5v5M21.5 9.5v5M6.5 12h11" /></svg></span>
|
||||
<span>{S.active ? 'Resume' : 'Start'}</span>
|
||||
<span>{S.active ? t('Resume') : t('Start')}</span>
|
||||
</button>
|
||||
<button className={on('stats') ? 'on' : ''} onClick={() => nav('/stats')}><Icon k="stats" /><span>Stats</span></button>
|
||||
<button className={on('library') ? 'on' : ''} onClick={() => nav('/library')}><Icon k="library" /><span>Exercises</span></button>
|
||||
<button className={on('stats') ? 'on' : ''} onClick={() => nav('/stats')}><Icon k="stats" /><span>{t('Stats')}</span></button>
|
||||
<button className={on('library') ? 'on' : ''} onClick={() => nav('/library')}><Icon k="library" /><span>{t('Exercises')}</span></button>
|
||||
</nav>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user