feat(i18n): navigator-detect default locale + locale-aware bone labels

- localeStore.readInitial now consults navigator.language(s) when
  localStorage is empty (first fr/en hit, FR fallback). Persisted user
  choice still wins.
- New helper src/anatomy/labels.ts (boneLabel(b, locale, fallback))
  with cross-language fallback so missing labels never render blank.
- AnatomyCanvas rewrites native SVG <title> tooltips per locale on
  mount and on locale change (upstream SVG ships titles as "FR / EN"
  concat; we replace with the active-locale label only). Detail-popup
  trigger titles ("🔍 Zoom: …") left intact.
- DetailModal + EditorRoute detail title prefix + vertebra picker
  title now route through useT()/boneLabel.
- ObservationCard.describeZone takes locale, picks bone.fr / bone.en.
- PDF: buildZoneLabels returns Map<id, { fr, en }> instead of FR-only;
  observationPage picks per locale with cross-language fallback.
- Tests: FindingsTreePicker + VertebraPicker reset locale to 'fr' in
  beforeEach (navigator-detect may land on EN in happy-dom).
- pdf.zoneLabels test updated to assert the new pair shape.

154/154 tests pass, lint clean, typecheck clean, build OK.

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:56:22 +02:00
1 parent 31bd82de58
commit 9cf8a66dad
13 files changed
+156 -35

No files matched your search

+21 -5
View File
@@ -16,17 +16,27 @@ export interface PdfExportOptions {
locale: Locale
}
/** Bilingual label pair surfaced to the PDF render layer. */
export interface ZoneLabelPair {
fr: string
en: string
}
/**
* Builds a `data-anno-id → French label` map by parsing every SVG the
* Builds a `data-anno-id → { fr, en }` map by parsing every SVG the
* species manifest knows about. Each SVG is loaded independently so a
* failure on the detail asset never prevents the main labels (or vice
* versa) from making it into the returned map.
* versa) from making it into the returned map. The PDF render layer
* picks the locale-appropriate label at draw time (falls back to the
* opposite language when one side is missing).
*
* Exported for unit testing — the editor calls it indirectly via
* `exportReportToPdf`.
*/
export async function buildZoneLabels(report: Report): Promise<Map<string, string>> {
const labels = new Map<string, string>()
export async function buildZoneLabels(
report: Report,
): Promise<Map<string, ZoneLabelPair>> {
const labels = new Map<string, ZoneLabelPair>()
const species = getSpecies(report.animal.speciesId)
if (!species) return labels
@@ -39,7 +49,13 @@ export async function buildZoneLabels(report: Report): Promise<Map<string, strin
try {
const root = await loadSvg(src)
parseSvgBones(root).forEach((b, id) => {
if (b.fr) labels.set(id, b.fr)
const existing = labels.get(id)
if (existing) {
if (!existing.fr && b.fr) existing.fr = b.fr
if (!existing.en && b.en) existing.en = b.en
} else if (b.fr || b.en) {
labels.set(id, { fr: b.fr, en: b.en })
}
})
} catch (err) {
console.warn(`buildZoneLabels: skipped ${src}`, err)
+6 -2
View File
@@ -5,6 +5,7 @@ import type { Finding, Observation } from '@/domain/schema/observation'
import type { SpeciesFindings } from '@/domain/schema/findings'
import type { Locale } from '@/i18n/types'
import { getDict } from '@/i18n'
import type { ZoneLabelPair } from '@/pdf/export'
import { drawHeader } from './header'
import { rasterizeSvg } from './svgToPng'
import { loadSvg } from '@/anatomy/svgLoader'
@@ -271,7 +272,7 @@ export async function addObservationPage(
observation: Observation,
obsIndex: number,
fonts: EmbeddedFonts,
zoneLabels: Map<string, string>,
zoneLabels: Map<string, ZoneLabelPair>,
findingsTree: SpeciesFindings | null,
locale: Locale,
): Promise<void> {
@@ -366,7 +367,10 @@ export async function addObservationPage(
const zonesText = observation.zones
.map((z) => {
const label = zoneLabels.get(z.boneId) ?? z.boneId
const pair = zoneLabels.get(z.boneId)
const label = pair
? (locale === 'en' ? pair.en || pair.fr : pair.fr || pair.en) || z.boneId
: z.boneId
const v = z.vertebrae?.length
? ` (${z.vertebrae.map((x) => `${x.region}${x.index}`).join(', ')})`
: ''