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
@@ -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}
|
||||
|
||||
Reference in new issue
Block a user