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:
Bastien ChanotandClaude Opus 4.7 committed 2026-05-20 07:11:40 +02:00
1 parent 359104ce88
commit d6027266bc
25 files changed
+390 -207

No files matched your search

@@ -5,6 +5,8 @@ import type {
} from '@/domain/schema/findings'
import type { Finding } from '@/domain/schema/observation'
import Button from '@/components/ui/Button'
import { useT } from '@/i18n/useT'
import { useLocaleStore } from '@/state/localeStore'
export interface FindingsTreePickerProps {
zoneId: string
@@ -53,6 +55,13 @@ export default function FindingsTreePicker({
selected,
onChange,
}: FindingsTreePickerProps) {
const t = useT()
const locale = useLocaleStore((s) => s.locale)
const nameOf = (node: { name_fr: string; name_en: string }) =>
locale === 'en' ? node.name_en : node.name_fr
const descOf = (node: { description_fr?: string; description_en?: string }) =>
locale === 'en' ? node.description_en : node.description_fr
const [path, setPath] = useState<string[]>([])
const currentNodes = useMemo<FindingNode[]>(() => {
@@ -67,19 +76,21 @@ export default function FindingsTreePicker({
)
const breadcrumb = useMemo<{ label: string; depth: number }[]>(() => {
const pick = (z: { name_fr: string; name_en: string }) =>
locale === 'en' ? z.name_en : z.name_fr
const crumbs: { label: string; depth: number }[] = [
{ label: tree.name_fr, depth: 0 },
{ label: pick(tree), depth: 0 },
]
let nodes: FindingNode[] = tree.categories
path.forEach((seg, i) => {
const n = nodes.find((x) => x.id === seg)
if (n) {
crumbs.push({ label: n.name_fr, depth: i + 1 })
crumbs.push({ label: pick(n), depth: i + 1 })
nodes = n.children ?? []
}
})
return crumbs
}, [tree, path])
}, [tree, path, locale])
function isLeafSelected(leafPath: string[]): boolean {
return selected.some(
@@ -141,9 +152,9 @@ export default function FindingsTreePicker({
})}
</div>
{focusedNode?.description_fr && (
{focusedNode && descOf(focusedNode) && (
<p className="text-xs italic text-[var(--color-ink-muted)]">
{focusedNode.description_fr}
{descOf(focusedNode)}
</p>
)}
@@ -152,22 +163,24 @@ export default function FindingsTreePicker({
size="sm"
variant="ghost"
onClick={() => setPath(path.slice(0, -1))}
aria-label="Retour au niveau précédent"
aria-label={t('findings.back_to_parent')}
>
← Retour
{t('findings.back')}
</Button>
)}
<ul className="space-y-1.5 max-h-64 overflow-auto pr-1">
{currentNodes.length === 0 ? (
<li className="text-sm text-[var(--color-ink-muted)]">
Aucune option disponible à ce niveau.
{t('findings.no_options')}
</li>
) : (
currentNodes.map((node) => {
const nodePath = [...path, node.id]
if (isLeaf(node)) {
const checked = isLeafSelected(nodePath)
const nodeLabel = nameOf(node)
const nodeDesc = descOf(node)
return (
<li key={node.id}>
<label className="flex items-start gap-2 cursor-pointer">
@@ -176,26 +189,26 @@ export default function FindingsTreePicker({
checked={checked}
onChange={() => toggleLeaf(nodePath, node)}
className="mt-1 accent-[var(--color-accent)]"
aria-label={node.name_fr}
aria-label={nodeLabel}
/>
<div className="flex-1">
<div className="flex items-center gap-2">
<span className="text-sm font-medium text-[var(--color-ink)]">
{node.name_fr}
{nodeLabel}
</span>
{node.requires_vet_referral && (
<span
title="Référer au vétérinaire"
aria-label="Référer au vétérinaire"
title={t('findings.vet_referral')}
aria-label={t('findings.vet_referral')}
className="text-[var(--color-danger)]"
>
⚠
</span>
)}
</div>
{node.description_fr && (
{nodeDesc && (
<div className="text-xs text-[var(--color-ink-muted)]">
{node.description_fr}
{nodeDesc}
</div>
)}
</div>
@@ -204,19 +217,25 @@ export default function FindingsTreePicker({
)
}
const selectedCount = countSelectedUnder(nodePath)
const nodeLabel = nameOf(node)
const selectedAria = `${selectedCount} ${
selectedCount > 1
? t('findings.selected_plural')
: t('findings.selected_singular')
}`
return (
<li key={node.id}>
<button
type="button"
onClick={() => setPath(nodePath)}
className="flex items-center justify-between w-full text-left text-sm px-2 py-1.5 rounded hover:bg-[var(--color-surface-strong)] text-[var(--color-ink)]"
aria-label={`Ouvrir ${node.name_fr}`}
aria-label={`${t('findings.open')} ${nodeLabel}`}
>
<span className="flex items-center gap-2">
<span>{node.name_fr}</span>
<span>{nodeLabel}</span>
{selectedCount > 0 && (
<span
aria-label={`${selectedCount} constat${selectedCount > 1 ? 's' : ''} sélectionné${selectedCount > 1 ? 's' : ''}`}
aria-label={selectedAria}
className="inline-flex items-center justify-center min-w-[20px] h-[20px] px-1.5 rounded-full text-[11px] font-semibold bg-[var(--color-accent)] text-white"
>
{selectedCount}
@@ -2,6 +2,7 @@ import { useState } from 'react'
import Input from '@/components/ui/Input'
import Button from '@/components/ui/Button'
import Badge from '@/components/ui/Badge'
import { useT } from '@/i18n/useT'
export interface FreeTextFindingInputProps {
items: string[]
@@ -13,6 +14,7 @@ export default function FreeTextFindingInput({
onChange,
}: FreeTextFindingInputProps) {
const [v, setV] = useState('')
const t = useT()
function add() {
const trimmed = v.trim()
@@ -31,17 +33,17 @@ export default function FreeTextFindingInput({
<Input
value={v}
onChange={(e) => setV(e.target.value)}
placeholder="Observation additionnelle (texte libre)"
placeholder={t('observation.free_placeholder')}
onKeyDown={(e) => {
if (e.key === 'Enter') {
e.preventDefault()
add()
}
}}
aria-label="Observation libre"
aria-label={t('observation.free_aria')}
/>
<Button onClick={add} variant="secondary">
Ajouter
{t('common.add')}
</Button>
</div>
{items.length > 0 && (
@@ -52,7 +54,7 @@ export default function FreeTextFindingInput({
{it}
<button
type="button"
aria-label={`Retirer ${it}`}
aria-label={`${t('observation.remove_zone')} ${it}`}
onClick={() => remove(i)}
className="ml-1 text-[var(--color-accent-strong)] hover:text-[var(--color-danger)]"
>
+43 -29
View File
@@ -19,6 +19,8 @@ import Textarea from '@/components/ui/Textarea'
import FindingsTreePicker from './FindingsTreePicker'
import FreeTextFindingInput from './FreeTextFindingInput'
import SeveritySelector from './SeveritySelector'
import { useT } from '@/i18n/useT'
import { useLocaleStore } from '@/state/localeStore'
export interface ObservationCardProps {
observation: Observation
@@ -66,6 +68,11 @@ export default function ObservationCard({
onOpenVertebraPicker,
onRemoveZone,
}: ObservationCardProps) {
const t = useT()
const locale = useLocaleStore((s) => s.locale)
const nameOf = (z: { name_fr: string; name_en: string }) =>
locale === 'en' ? z.name_en : z.name_fr
// Per-zone picker accordion — only one tree picker open at a time,
// matching the observation-card accordion semantics. Closed by default
// so the card stays compact when first expanded.
@@ -75,6 +82,15 @@ export default function ObservationCard({
const findingCount =
observation.findings.length + observation.freeTextFindings.length
const zoneCountLabel =
zoneCount > 1
? t('observation.zone_label_plural')
: t('observation.zone_label_singular')
const findingCountLabel =
findingCount > 1
? t('observation.finding_label_plural')
: t('observation.finding_label_singular')
function onHeaderKey(event: React.KeyboardEvent<HTMLDivElement>) {
if (event.key === 'Enter' || event.key === ' ') {
event.preventDefault()
@@ -89,11 +105,6 @@ export default function ObservationCard({
}
}
// SVG data-anno-id values are opaque generator strings (e.g.
// "point-mpbyk..."); the JSON catalog keys observations by stable
// human zone names (e.g. "sphenoid"). Bridge the two by matching the
// bone's FR/EN labels against the catalog labels — EN exact first,
// then FR, then small typos / abbreviations via fuzzy scoring.
const zonesArray = useMemo(
() => (findings ? Object.values(findings.zones) : []),
[findings],
@@ -131,14 +142,14 @@ export default function ObservationCard({
role="button"
tabIndex={0}
aria-expanded={expanded}
aria-label={`${expanded ? 'Réduire' : 'Développer'} l'observation ${index + 1}`}
aria-label={`${expanded ? t('observation.collapse_aria') : t('observation.expand_aria')} ${index + 1}`}
onClick={onToggle}
onKeyDown={onHeaderKey}
className="flex items-start justify-between gap-3 p-4 cursor-pointer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]/40 rounded-2xl"
>
<div className="flex-1 min-h-[60px] text-left">
<div className="flex items-center gap-2 mb-2">
<Badge tone="neutral">Observation #{index + 1}</Badge>
<Badge tone="neutral">{t('observation.badge_n')}{index + 1}</Badge>
{observation.severity && (
<Badge
tone={
@@ -149,13 +160,12 @@ export default function ObservationCard({
: 'neutral'
}
>
{observation.severity}
{t(`severity.${observation.severity}`)}
</Badge>
)}
</div>
<div className="text-sm text-[var(--color-ink-muted)]">
{zoneCount} zone{zoneCount > 1 ? 's' : ''} · {findingCount} constat
{findingCount > 1 ? 's' : ''}
{zoneCount} {zoneCountLabel} · {findingCount} {findingCountLabel}
</div>
{!expanded && observation.comment && (
<p className="mt-2 text-sm line-clamp-2 text-[var(--color-ink)]">
@@ -172,7 +182,7 @@ export default function ObservationCard({
variant="ghost"
disabled={!canMoveUp}
onClick={stop(onMoveUp)}
aria-label="Monter"
aria-label={t('common.move_up')}
>
↑
</Button>
@@ -181,7 +191,7 @@ export default function ObservationCard({
variant="ghost"
disabled={!canMoveDown}
onClick={stop(onMoveDown)}
aria-label="Descendre"
aria-label={t('common.move_down')}
>
↓
</Button>
@@ -189,7 +199,7 @@ export default function ObservationCard({
size="sm"
variant="ghost"
onClick={stop(onDelete)}
aria-label="Supprimer"
aria-label={t('common.delete')}
>
🗑
</Button>
@@ -197,7 +207,7 @@ export default function ObservationCard({
size="sm"
variant="ghost"
onClick={stop(onToggle)}
aria-label={expanded ? 'Réduire' : 'Développer'}
aria-label={expanded ? t('common.collapse') : t('common.expand')}
>
{expanded ? '▲' : '▼'}
</Button>
@@ -216,11 +226,10 @@ export default function ObservationCard({
>
<div className="px-4 pb-4 pt-2 border-t border-[var(--color-border)] space-y-6">
<section>
<Label>Zones sélectionnées</Label>
<Label>{t('observation.zones_label')}</Label>
{observation.zones.length === 0 ? (
<p className="text-sm text-[var(--color-ink-muted)]">
Cliquez sur les zones du schéma pour les ajouter à cette
observation.
{t('observation.zones_empty')}
</p>
) : (
<ul className="flex flex-wrap gap-2">
@@ -237,14 +246,14 @@ export default function ObservationCard({
type="button"
onClick={() => onOpenVertebraPicker(i)}
className="underline text-xs text-[var(--color-accent-strong)]"
title="Préciser les vertèbres pour cette zone"
title={t('observation.vertebrae_button_title')}
>
Vertèbres…
{t('observation.vertebrae_button')}
</button>
)}
<button
type="button"
aria-label={`Retirer ${b?.fr ?? z.boneId}`}
aria-label={`${t('observation.remove_zone')} ${b?.fr ?? z.boneId}`}
onClick={() => onRemoveZone(i)}
className="ml-1 text-[var(--color-accent-strong)]"
>
@@ -259,12 +268,12 @@ export default function ObservationCard({
</section>
<section>
<Label>Constats (référentiel)</Label>
<Label>{t('observation.findings_catalog_label')}</Label>
{zonesWithTree.length === 0 ? (
<p className="text-sm text-[var(--color-ink-muted)]">
{observation.zones.length === 0
? 'Sélectionnez une zone pour accéder au référentiel.'
: 'Aucun référentiel disponible pour ces zones. Utilisez le texte libre ci-dessous.'}
? t('observation.findings_pick_zone_first')
: t('observation.findings_no_catalog')}
</p>
) : (
<ul className="space-y-2">
@@ -273,6 +282,11 @@ export default function ObservationCard({
const selectedCount = observation.findings.filter(
(f) => f.zoneId === tree.id,
).length
const selectedAria = `${selectedCount} ${
selectedCount > 1
? t('findings.selected_plural')
: t('findings.selected_singular')
}`
return (
<li
key={tree.id}
@@ -294,11 +308,11 @@ export default function ObservationCard({
>
<span className="flex items-center gap-2">
<span className="text-sm font-medium text-[var(--color-ink)]">
{tree.name_fr}
{nameOf(tree)}
</span>
{selectedCount > 0 && (
<span
aria-label={`${selectedCount} constat${selectedCount > 1 ? 's' : ''} sélectionné${selectedCount > 1 ? 's' : ''}`}
aria-label={selectedAria}
className="inline-flex items-center justify-center min-w-[20px] h-[20px] px-1.5 rounded-full text-[11px] font-semibold bg-[var(--color-accent)] text-white"
>
{selectedCount}
@@ -344,7 +358,7 @@ export default function ObservationCard({
</section>
<section>
<Label>Constats (texte libre)</Label>
<Label>{t('observation.findings_free_label')}</Label>
<FreeTextFindingInput
items={observation.freeTextFindings}
onChange={(items) =>
@@ -354,7 +368,7 @@ export default function ObservationCard({
</section>
<section>
<Label>Sévérité</Label>
<Label>{t('observation.severity_label')}</Label>
<SeveritySelector
value={observation.severity}
onChange={(s) => onChange({ ...observation, severity: s })}
@@ -363,7 +377,7 @@ export default function ObservationCard({
<section>
<Label htmlFor={`obs-comment-${observation.id}`}>
Commentaire
{t('observation.comment_label')}
</Label>
<Textarea
id={`obs-comment-${observation.id}`}
@@ -371,7 +385,7 @@ export default function ObservationCard({
onChange={(e) =>
onChange({ ...observation, comment: e.target.value })
}
placeholder="Notes cliniques détaillées…"
placeholder={t('observation.comment_placeholder')}
/>
</section>
</div>
@@ -3,6 +3,7 @@ import type { SpeciesFindings } from '@/domain/schema/findings'
import type { Bone } from '@/anatomy/types'
import ObservationCard from './ObservationCard'
import Button from '@/components/ui/Button'
import { useT } from '@/i18n/useT'
export interface ObservationListProps {
observations: Observation[]
@@ -34,20 +35,20 @@ export default function ObservationList({
onOpenVertebraPicker,
onRemoveZone,
}: ObservationListProps) {
const t = useT()
return (
<div className="space-y-3">
<div className="flex items-center justify-between">
<h2 className="font-serif text-xl text-[var(--color-ink)]">
Observations
{t('observation.section_title')}
</h2>
<Button size="sm" onClick={onAdd}>
+ Nouvelle observation
{t('observation.add')}
</Button>
</div>
{observations.length === 0 ? (
<p className="text-sm text-[var(--color-ink-muted)]">
Aucune observation. Cliquez sur &quot;+ Nouvelle observation&quot;
puis sur les zones du schéma.
{t('observation.empty')}
</p>
) : (
<ul className="space-y-2">
@@ -1,4 +1,5 @@
import type { Severity } from '@/domain/schema/observation'
import { useT } from '@/i18n/useT'
export interface SeveritySelectorProps {
value: Severity | undefined
@@ -13,8 +14,9 @@ const COLORS: Record<Severity, string> = {
}
export default function SeveritySelector({ value, onChange }: SeveritySelectorProps) {
const t = useT()
return (
<div role="radiogroup" aria-label="Sévérité" className="flex gap-2">
<div role="radiogroup" aria-label={t('severity.aria')} className="flex gap-2">
{SEVERITIES.map((s) => (
<button
key={s}
@@ -28,7 +30,7 @@ export default function SeveritySelector({ value, onChange }: SeveritySelectorPr
: 'border-[var(--color-border)] text-[var(--color-ink-muted)]',
].join(' ')}
>
{s}
{t(`severity.${s}`)}
</button>
))}
</div>
+19 -14
View File
@@ -4,13 +4,15 @@ import Button from '@/components/ui/Button'
import Chip from '@/components/ui/Chip'
import type { Vertebra, VertebralRegion } from '@/domain/schema/observation'
import type { VertebralFormula } from '@/domain/species/types'
import { useT } from '@/i18n/useT'
const REGION_LABELS: Record<VertebralRegion, string> = {
C: 'Cervicales',
T: 'Thoraciques',
L: 'Lombaires',
S: 'Sacrales',
Cd: 'Caudales',
const REGIONS: VertebralRegion[] = ['C', 'T', 'L', 'S', 'Cd']
const REGION_KEY: Record<VertebralRegion, string> = {
C: 'vertebra.region.C',
T: 'vertebra.region.T',
L: 'vertebra.region.L',
S: 'vertebra.region.S',
Cd: 'vertebra.region.Cd',
}
/**
@@ -23,8 +25,6 @@ export function regionFromLabel(label: string): VertebralRegion | undefined {
.normalize('NFD')
.replace(/\p{Diacritic}/gu, '')
.toLowerCase()
// Order matters: 'caudal'/'coccyg' before 'cervic' is fine; just be
// explicit so no root subsumes another.
if (norm.includes('cervic')) return 'C'
if (norm.includes('thorac') || norm.includes('dors')) return 'T'
if (norm.includes('lombair') || norm.includes('lumbar')) return 'L'
@@ -53,6 +53,7 @@ export default function VertebraPicker({
title,
initialRegion,
}: VertebraPickerProps) {
const t = useT()
const [selected, setSelected] = useState<Vertebra[]>(initial)
const [activeRegion, setActiveRegion] = useState<VertebralRegion>(
() => initial[0]?.region ?? initialRegion ?? 'C',
@@ -84,7 +85,7 @@ export default function VertebraPicker({
return (
<Dialog open={open} onClose={onClose} title={title} size="lg">
<div role="tablist" className="flex flex-wrap gap-2 mb-4">
{(Object.keys(REGION_LABELS) as VertebralRegion[]).map((r) => (
{REGIONS.map((r) => (
<button
key={r}
role="tab"
@@ -97,7 +98,7 @@ export default function VertebraPicker({
: 'bg-white text-[var(--color-ink)] border-[var(--color-border)]',
].join(' ')}
>
{REGION_LABELS[r]}
{t(REGION_KEY[r])}
</button>
))}
</div>
@@ -115,13 +116,17 @@ export default function VertebraPicker({
</div>
<div className="flex flex-wrap items-center gap-2 mb-6">
<Button variant="ghost" size="sm" onClick={() => all(activeRegion, count)}>Tout cocher</Button>
<Button variant="ghost" size="sm" onClick={() => none(activeRegion)}>Tout décocher</Button>
<Button variant="ghost" size="sm" onClick={() => all(activeRegion, count)}>
{t('vertebra.check_all')}
</Button>
<Button variant="ghost" size="sm" onClick={() => none(activeRegion)}>
{t('vertebra.uncheck_all')}
</Button>
</div>
<div className="flex justify-end gap-2">
<Button variant="ghost" onClick={onClose}>Annuler</Button>
<Button onClick={() => onConfirm(selected)}>Valider</Button>
<Button variant="ghost" onClick={onClose}>{t('common.cancel')}</Button>
<Button onClick={() => onConfirm(selected)}>{t('common.confirm')}</Button>
</div>
</Dialog>
)