Files
faunosteo/src/components/brand/LanguageSwitcher.tsx
T
Bastien ChanotandClaude Opus 4.7 d6027266bc 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>
2026-05-20 07:11:40 +02:00

41 lines
1.3 KiB
TypeScript

import { useLocaleStore } from '@/state/localeStore'
import type { Locale } from '@/i18n/types'
const ITEMS: { value: Locale; label: string; ariaLabel: string }[] = [
{ value: 'fr', label: 'FR', ariaLabel: 'Passer en français' },
{ value: 'en', label: 'EN', ariaLabel: 'Switch to English' },
]
export default function LanguageSwitcher() {
const locale = useLocaleStore((s) => s.locale)
const setLocale = useLocaleStore((s) => s.setLocale)
return (
<div
role="group"
aria-label="Language"
className="inline-flex rounded-full border border-[var(--color-border)] overflow-hidden text-xs font-medium"
>
{ITEMS.map((item) => {
const active = locale === item.value
return (
<button
key={item.value}
type="button"
aria-label={item.ariaLabel}
aria-pressed={active}
onClick={() => setLocale(item.value)}
className={[
'px-2.5 py-1 transition focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]',
active
? 'bg-[var(--color-accent)] text-white'
: 'text-[var(--color-ink)] hover:bg-[var(--color-surface-strong)]',
].join(' ')}
>
{item.label}
</button>
)
})}
</div>
)
}