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
+18
-11
@@ -1,6 +1,8 @@
|
||||
import { PDFDocument } from 'pdf-lib'
|
||||
import type { Report } from '@/domain/schema/report'
|
||||
import type { SpeciesFindings } from '@/domain/schema/findings'
|
||||
import type { Locale } from '@/i18n/types'
|
||||
import { getDict } from '@/i18n'
|
||||
import { embedFonts } from './fonts'
|
||||
import { addObservationPage } from './render/observationPage'
|
||||
import { addConclusionPage } from './render/conclusionPage'
|
||||
@@ -10,6 +12,10 @@ import { loadSvg } from '@/anatomy/svgLoader'
|
||||
import { parseSvgBones } from '@/anatomy/svgConvention'
|
||||
import { getSpecies } from '@/domain/species/registry'
|
||||
|
||||
export interface PdfExportOptions {
|
||||
locale: Locale
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a `data-anno-id → French label` map by parsing every SVG the
|
||||
* species manifest knows about. Each SVG is loaded independently so a
|
||||
@@ -36,9 +42,6 @@ export async function buildZoneLabels(report: Report): Promise<Map<string, strin
|
||||
if (b.fr) labels.set(id, b.fr)
|
||||
})
|
||||
} catch (err) {
|
||||
// Asset unavailable (404 / fetch failure / parse error). Log and
|
||||
// continue — observers downstream fall back to the raw bone id,
|
||||
// which is preferable to crashing the whole export.
|
||||
console.warn(`buildZoneLabels: skipped ${src}`, err)
|
||||
}
|
||||
}),
|
||||
@@ -50,9 +53,7 @@ export async function buildZoneLabels(report: Report): Promise<Map<string, strin
|
||||
/**
|
||||
* Loads the parsed findings catalog for a species so the PDF renderer
|
||||
* can resolve a Finding's `zoneId` (JSON catalog key) back to its
|
||||
* human-readable zone name. Returns null if the species lacks a
|
||||
* catalog or the lazy import fails — the PDF still renders, but
|
||||
* per-zone groups fall back to the raw zoneId.
|
||||
* human-readable zone name.
|
||||
*/
|
||||
async function loadSpeciesFindings(
|
||||
speciesId: string,
|
||||
@@ -68,11 +69,16 @@ async function loadSpeciesFindings(
|
||||
}
|
||||
}
|
||||
|
||||
export async function exportReportToPdf(report: Report): Promise<Uint8Array> {
|
||||
export async function exportReportToPdf(
|
||||
report: Report,
|
||||
opts: PdfExportOptions,
|
||||
): Promise<Uint8Array> {
|
||||
const { locale } = opts
|
||||
const dict = getDict(locale)
|
||||
const pdfDoc = await PDFDocument.create()
|
||||
pdfDoc.setTitle(`Bilan ostéo — ${report.animal.name}`)
|
||||
pdfDoc.setTitle(`${dict['pdf.title.suffix.bilan']}${report.animal.name}`)
|
||||
pdfDoc.setAuthor(report.practitioner.name)
|
||||
pdfDoc.setSubject("Bilan d'ostéopathie animalière")
|
||||
pdfDoc.setSubject(dict['pdf.subject'])
|
||||
pdfDoc.setCreationDate(new Date())
|
||||
pdfDoc.setModificationDate(new Date())
|
||||
|
||||
@@ -89,12 +95,13 @@ export async function exportReportToPdf(report: Report): Promise<Uint8Array> {
|
||||
fonts,
|
||||
zoneLabels,
|
||||
findingsTree,
|
||||
locale,
|
||||
)
|
||||
}
|
||||
await addConclusionPage(pdfDoc, report, fonts)
|
||||
await addConclusionPage(pdfDoc, report, fonts, locale)
|
||||
|
||||
const pages = pdfDoc.getPages()
|
||||
pages.forEach((page, idx) => drawFooter(page, fonts, idx + 1, pages.length))
|
||||
pages.forEach((page, idx) => drawFooter(page, fonts, idx + 1, pages.length, locale))
|
||||
|
||||
await attachReportJson(pdfDoc, report)
|
||||
return pdfDoc.save()
|
||||
|
||||
Reference in new issue
Block a user