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
@@ -0,0 +1,24 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest'
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import LanguageSwitcher from '@/components/brand/LanguageSwitcher'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
|
||||
beforeEach(() => {
|
||||
useLocaleStore.setState({ locale: 'fr' })
|
||||
})
|
||||
|
||||
describe('LanguageSwitcher', () => {
|
||||
it('reflects the active locale via aria-pressed', () => {
|
||||
render(<LanguageSwitcher />)
|
||||
expect(screen.getByRole('button', { name: /français/i })).toHaveAttribute('aria-pressed', 'true')
|
||||
expect(screen.getByRole('button', { name: /english/i })).toHaveAttribute('aria-pressed', 'false')
|
||||
})
|
||||
|
||||
it('clicking EN updates the store', async () => {
|
||||
const user = userEvent.setup()
|
||||
render(<LanguageSwitcher />)
|
||||
await user.click(screen.getByRole('button', { name: /english/i }))
|
||||
expect(useLocaleStore.getState().locale).toBe('en')
|
||||
})
|
||||
})
|
||||
@@ -1,17 +1,29 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { formatDateFr, todayIso, nowIso } from '@/lib/dates'
|
||||
import { formatDate, todayIso, nowIso } from '@/lib/dates'
|
||||
|
||||
describe('formatDateFr', () => {
|
||||
it('formats an ISO date as "18 mai 2026"', () => {
|
||||
expect(formatDateFr('2026-05-18')).toBe('18 mai 2026')
|
||||
describe('formatDate fr', () => {
|
||||
it('formats "2026-05-18" as "18 mai 2026"', () => {
|
||||
expect(formatDate('2026-05-18', 'fr')).toBe('18 mai 2026')
|
||||
})
|
||||
|
||||
it('formats a leading-zero day correctly', () => {
|
||||
expect(formatDateFr('2026-01-03')).toBe('3 janvier 2026')
|
||||
it('drops leading zero on the day', () => {
|
||||
expect(formatDate('2026-01-03', 'fr')).toBe('3 janvier 2026')
|
||||
})
|
||||
})
|
||||
|
||||
describe('formatDate en', () => {
|
||||
it('formats "2026-05-18" as "May 18, 2026"', () => {
|
||||
expect(formatDate('2026-05-18', 'en')).toBe('May 18, 2026')
|
||||
})
|
||||
|
||||
it('throws on invalid input', () => {
|
||||
expect(() => formatDateFr('not-a-date')).toThrow()
|
||||
it('drops leading zero on the day', () => {
|
||||
expect(formatDate('2026-01-03', 'en')).toBe('January 3, 2026')
|
||||
})
|
||||
})
|
||||
|
||||
describe('formatDate edge', () => {
|
||||
it('throws on invalid ISO input', () => {
|
||||
expect(() => formatDate('not-a-date', 'fr')).toThrow()
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ describe('PDF roundtrip', () => {
|
||||
})
|
||||
|
||||
it('roundtrips a minimal report (no observations)', async () => {
|
||||
const bytes = await exportReportToPdf(report)
|
||||
const bytes = await exportReportToPdf(report, { locale: 'fr' })
|
||||
const imported = await importReportFromPdf(bytes)
|
||||
expect(imported.animal.name).toBe('Mistral')
|
||||
expect(imported.version).toBe(2)
|
||||
|
||||
Reference in new issue
Block a user