feat(i18n): migrate site + PDF to locale-aware rendering
- formatDate(iso, locale) replaces formatDateFr in src/lib/dates.ts
- exportReportToPdf(report, { locale }) takes explicit locale option
- LanguageSwitcher segmented FR | EN toggle added; integrated in
ReportHeader, HomeRoute, NewReportRoute
- All routes (Home, NewReport, Editor, NotFound) + observation
components (FindingsTreePicker, ObservationCard, FreeTextFindingInput,
SeveritySelector, VertebraPicker, ObservationList) + report forms
(PractitionerForm, AnimalForm, ConclusionPanel, NextAppointmentPicker)
route hardcoded FR via useT()
- PDF render functions (export.ts, header.ts, footer.ts,
observationPage.ts, conclusionPage.ts) take a locale arg and read
static labels from the dict snapshot at call time
- Catalog finding leaf labels rendered via labelFr/EnSnapshot per locale
- description_fr / scope_disclaimer stay FR-only (out of scope —
vet-expert authoring needed for EN copy)
- LanguageSwitcher unit test (2) + lib.dates locale tests (7) cover
the new behavior
151/151 tests pass, lint 0, typecheck clean, vite build OK
(902KB main + 15KB lazy pathologies chunk).
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
1 parent
359104ce88
commit
d6027266bc
25 files changed
+390
-207
No files matched your search
@@ -23,11 +23,15 @@ import type { SpeciesFindings } from '@/domain/schema/findings'
|
||||
import type { Practitioner } from '@/domain/schema/practitioner'
|
||||
import type { Animal, Owner } from '@/domain/schema/animal'
|
||||
import { exportReportToPdf } from '@/pdf/export'
|
||||
import { useT } from '@/i18n/useT'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
|
||||
const DISCLAIMER_FLAG = 'osteo:disclaimer-shown'
|
||||
|
||||
export default function EditorRoute() {
|
||||
const navigate = useNavigate()
|
||||
const t = useT()
|
||||
const locale = useLocaleStore((s) => s.locale)
|
||||
const report = useReportStore((s) => s.report)
|
||||
const activeIndex = useReportStore((s) => s.activeObservationIndex)
|
||||
const addObservation = useReportStore((s) => s.addObservation)
|
||||
@@ -246,7 +250,7 @@ export default function EditorRoute() {
|
||||
if (!report) return
|
||||
setExporting(true)
|
||||
try {
|
||||
const bytes = await exportReportToPdf(report)
|
||||
const bytes = await exportReportToPdf(report, { locale })
|
||||
const blob = new Blob([bytes as BlobPart], { type: 'application/pdf' })
|
||||
const url = URL.createObjectURL(blob)
|
||||
const a = document.createElement('a')
|
||||
@@ -256,9 +260,7 @@ export default function EditorRoute() {
|
||||
URL.revokeObjectURL(url)
|
||||
} catch (err) {
|
||||
console.error('PDF export failed', err)
|
||||
window.alert(
|
||||
"Échec de la génération du PDF. Réessayez ou contactez le support.",
|
||||
)
|
||||
window.alert(t('editor.export_failed'))
|
||||
} finally {
|
||||
setExporting(false)
|
||||
}
|
||||
@@ -309,7 +311,7 @@ export default function EditorRoute() {
|
||||
/>
|
||||
<div className="flex justify-end">
|
||||
<Button onClick={onExport} disabled={exporting}>
|
||||
{exporting ? 'Génération…' : 'Exporter en PDF'}
|
||||
{exporting ? t('editor.exporting') : t('editor.export')}
|
||||
</Button>
|
||||
</div>
|
||||
</section>
|
||||
@@ -331,7 +333,7 @@ export default function EditorRoute() {
|
||||
<Dialog
|
||||
open={editOpen}
|
||||
onClose={closeEditInfos}
|
||||
title="Modifier les informations"
|
||||
title={t('editor.edit_dialog_title')}
|
||||
size="lg"
|
||||
>
|
||||
<div className="space-y-8">
|
||||
@@ -353,7 +355,7 @@ export default function EditorRoute() {
|
||||
/>
|
||||
<div className="flex gap-3 justify-end pt-2 border-t border-[var(--color-border)]">
|
||||
<Button variant="ghost" onClick={closeEditInfos}>
|
||||
Annuler
|
||||
{t('common.cancel')}
|
||||
</Button>
|
||||
<Button
|
||||
onClick={saveEditInfos}
|
||||
@@ -363,7 +365,7 @@ export default function EditorRoute() {
|
||||
!editDraft.owner.name.trim()
|
||||
}
|
||||
>
|
||||
Enregistrer
|
||||
{t('common.save')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -374,13 +376,13 @@ export default function EditorRoute() {
|
||||
<Dialog
|
||||
open
|
||||
onClose={acknowledgeDisclaimer}
|
||||
title="Périmètre légal de l'ostéopathie animale"
|
||||
title={t('editor.disclaimer_title')}
|
||||
size="md"
|
||||
>
|
||||
<div className="space-y-4">
|
||||
<p className="text-sm text-[var(--color-ink)]">{disclaimer}</p>
|
||||
<div className="flex justify-end">
|
||||
<Button onClick={acknowledgeDisclaimer}>Compris</Button>
|
||||
<Button onClick={acknowledgeDisclaimer}>{t('common.understood')}</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog>
|
||||
@@ -406,7 +408,7 @@ export default function EditorRoute() {
|
||||
}}
|
||||
initial={activeObs.zones[vertebraTarget].vertebrae ?? []}
|
||||
formula={species.vertebralFormula}
|
||||
title={`Préciser les vertèbres — ${bones.get(activeObs.zones[vertebraTarget].boneId)?.fr ?? ''}`}
|
||||
title={`${t('vertebra.title_prefix')}${bones.get(activeObs.zones[vertebraTarget].boneId)?.fr ?? ''}`}
|
||||
initialRegion={(() => {
|
||||
const b = bones.get(activeObs.zones[vertebraTarget].boneId)
|
||||
return regionFromLabel(b?.fr ?? '') ?? regionFromLabel(b?.en ?? '')
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useRef, useState } from 'react'
|
||||
import Brand from '@/components/brand/Brand'
|
||||
import LanguageSwitcher from '@/components/brand/LanguageSwitcher'
|
||||
import Button from '@/components/ui/Button'
|
||||
import Card from '@/components/ui/Card'
|
||||
import { useConfig } from '@/app/providers/ConfigProvider'
|
||||
import { importReportFromPdf, ImportError } from '@/pdf/import'
|
||||
import { useReportStore } from '@/state/reportStore'
|
||||
import { useT } from '@/i18n/useT'
|
||||
|
||||
export default function HomeRoute() {
|
||||
const navigate = useNavigate()
|
||||
@@ -14,6 +16,7 @@ export default function HomeRoute() {
|
||||
const hydrate = useReportStore((s) => s.hydrateReport)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [busy, setBusy] = useState(false)
|
||||
const t = useT()
|
||||
|
||||
async function onPickFile(e: React.ChangeEvent<HTMLInputElement>) {
|
||||
const file = e.target.files?.[0]
|
||||
@@ -26,7 +29,7 @@ export default function HomeRoute() {
|
||||
hydrate(report)
|
||||
navigate('/editor')
|
||||
} catch (err) {
|
||||
setError(err instanceof ImportError ? err.message : "Erreur de lecture du PDF.")
|
||||
setError(err instanceof ImportError ? err.message : t('home.import.error_generic'))
|
||||
} finally {
|
||||
setBusy(false)
|
||||
if (fileRef.current) fileRef.current.value = ''
|
||||
@@ -37,25 +40,24 @@ export default function HomeRoute() {
|
||||
<main className="min-h-screen flex flex-col">
|
||||
<header className="px-6 py-4 border-b border-[var(--color-border)] flex items-center justify-between">
|
||||
<Brand size="lg" />
|
||||
<span className="text-sm text-[var(--color-ink-muted)]">{cfg.tagline}</span>
|
||||
<div className="flex items-center gap-4">
|
||||
<LanguageSwitcher />
|
||||
<span className="text-sm text-[var(--color-ink-muted)]">{cfg.tagline}</span>
|
||||
</div>
|
||||
</header>
|
||||
<section className="flex-1 grid place-items-center px-6">
|
||||
<div className="grid gap-4 md:grid-cols-2 max-w-3xl w-full">
|
||||
<Card className="p-6 space-y-4">
|
||||
<h2 className="font-serif text-2xl">Nouveau bilan</h2>
|
||||
<p className="text-sm text-[var(--color-ink-muted)]">
|
||||
Démarrer un nouveau bilan d'ostéopathie sur un animal.
|
||||
</p>
|
||||
<Button onClick={() => navigate('/new')} size="lg">Commencer</Button>
|
||||
<h2 className="font-serif text-2xl">{t('home.new_report.title')}</h2>
|
||||
<p className="text-sm text-[var(--color-ink-muted)]">{t('home.new_report.description')}</p>
|
||||
<Button onClick={() => navigate('/new')} size="lg">{t('home.new_report.cta')}</Button>
|
||||
</Card>
|
||||
<Card className="p-6 space-y-4">
|
||||
<h2 className="font-serif text-2xl">Importer un PDF</h2>
|
||||
<p className="text-sm text-[var(--color-ink-muted)]">
|
||||
Reprendre un bilan précédent généré par cette application pour effectuer un suivi.
|
||||
</p>
|
||||
<h2 className="font-serif text-2xl">{t('home.import.title')}</h2>
|
||||
<p className="text-sm text-[var(--color-ink-muted)]">{t('home.import.description')}</p>
|
||||
<input ref={fileRef} type="file" accept="application/pdf,.pdf" className="hidden" onChange={onPickFile} />
|
||||
<Button variant="secondary" size="lg" onClick={() => fileRef.current?.click()} disabled={busy}>
|
||||
{busy ? 'Lecture…' : 'Choisir un PDF'}
|
||||
{busy ? t('home.import.loading') : t('home.import.cta')}
|
||||
</Button>
|
||||
{error && <p className="text-sm text-red-700">{error}</p>}
|
||||
</Card>
|
||||
|
||||
@@ -3,16 +3,19 @@ import { Link, useNavigate } from 'react-router-dom'
|
||||
import PractitionerForm from '@/components/report/PractitionerForm'
|
||||
import AnimalForm from '@/components/report/AnimalForm'
|
||||
import Brand from '@/components/brand/Brand'
|
||||
import LanguageSwitcher from '@/components/brand/LanguageSwitcher'
|
||||
import Button from '@/components/ui/Button'
|
||||
import Input from '@/components/ui/Input'
|
||||
import Label from '@/components/ui/Label'
|
||||
import { todayIso } from '@/lib/dates'
|
||||
import { readCachedPractitioner, writeCachedPractitioner } from '@/state/practitionerCache'
|
||||
import { useReportStore } from '@/state/reportStore'
|
||||
import { useT } from '@/i18n/useT'
|
||||
|
||||
export default function NewReportRoute() {
|
||||
const navigate = useNavigate()
|
||||
const initReport = useReportStore((s) => s.initReport)
|
||||
const t = useT()
|
||||
|
||||
const [practitioner, setPractitioner] = useState({ name: '' })
|
||||
const [animal, setAnimal] = useState({ speciesId: 'equine', name: '' })
|
||||
@@ -43,34 +46,32 @@ export default function NewReportRoute() {
|
||||
|
||||
return (
|
||||
<main className="min-h-screen">
|
||||
<header className="px-6 py-4 border-b border-[var(--color-border)] flex items-center gap-3">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => navigate('/')}
|
||||
aria-label="Retour à l'accueil"
|
||||
>
|
||||
← Accueil
|
||||
</Button>
|
||||
<Link
|
||||
to="/"
|
||||
aria-label="Retour à l'accueil"
|
||||
className="rounded-md px-1 py-0.5 hover:opacity-80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]"
|
||||
>
|
||||
<Brand />
|
||||
</Link>
|
||||
<header className="px-6 py-4 border-b border-[var(--color-border)] flex items-center justify-between">
|
||||
<div className="flex items-center gap-3">
|
||||
<Button variant="ghost" size="sm" onClick={() => navigate('/')} aria-label={t('common.back_to_home')}>
|
||||
← {t('common.home')}
|
||||
</Button>
|
||||
<Link
|
||||
to="/"
|
||||
aria-label={t('common.back_to_home')}
|
||||
className="rounded-md px-1 py-0.5 hover:opacity-80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]"
|
||||
>
|
||||
<Brand />
|
||||
</Link>
|
||||
</div>
|
||||
<LanguageSwitcher />
|
||||
</header>
|
||||
<div className="max-w-3xl mx-auto px-6 py-8 space-y-8">
|
||||
<h1 className="font-serif text-3xl">Nouveau bilan</h1>
|
||||
<h1 className="font-serif text-3xl">{t('new_report.title')}</h1>
|
||||
<div>
|
||||
<Label htmlFor="date">Date du bilan</Label>
|
||||
<Label htmlFor="date">{t('new_report.date_label')}</Label>
|
||||
<Input id="date" type="date" value={date} onChange={(e) => setDate(e.target.value)} />
|
||||
</div>
|
||||
<PractitionerForm value={practitioner} onChange={setPractitioner} />
|
||||
<AnimalForm animal={animal} owner={owner} onChangeAnimal={setAnimal} onChangeOwner={setOwner} />
|
||||
<div className="flex gap-3 justify-end">
|
||||
<Button variant="ghost" onClick={() => navigate('/')}>Annuler</Button>
|
||||
<Button disabled={!canSubmit} onClick={submit}>Démarrer le bilan</Button>
|
||||
<Button variant="ghost" onClick={() => navigate('/')}>{t('common.cancel')}</Button>
|
||||
<Button disabled={!canSubmit} onClick={submit}>{t('new_report.submit')}</Button>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import Button from '@/components/ui/Button'
|
||||
import { useT } from '@/i18n/useT'
|
||||
|
||||
export default function NotFoundRoute() {
|
||||
const navigate = useNavigate()
|
||||
const t = useT()
|
||||
return (
|
||||
<main className="min-h-screen grid place-items-center">
|
||||
<div className="text-center space-y-4">
|
||||
<h1 className="font-serif text-4xl">Page introuvable</h1>
|
||||
<p className="text-[var(--color-ink-muted)]">Le chemin demandé n'existe pas.</p>
|
||||
<Button onClick={() => navigate('/')}>Retour à l'accueil</Button>
|
||||
<h1 className="font-serif text-4xl">{t('not_found.title')}</h1>
|
||||
<p className="text-[var(--color-ink-muted)]">{t('not_found.description')}</p>
|
||||
<Button onClick={() => navigate('/')}>{t('common.back_to_home')}</Button>
|
||||
</div>
|
||||
</main>
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user