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:
1 parent
31bd82de58
commit
9cf8a66dad
13 files changed
+156
-35
No files matched your search
@@ -1,9 +1,17 @@
|
||||
import { describe, it, expect, vi } from 'vitest'
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import FindingsTreePicker from '@/components/observation/FindingsTreePicker'
|
||||
import type { ZoneFindings } from '@/domain/schema/findings'
|
||||
import type { Finding } from '@/domain/schema/observation'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
|
||||
beforeEach(() => {
|
||||
// Navigator-detected default may land on EN in happy-dom; force FR so the
|
||||
// FR-label assertions in this file remain stable regardless of the runner's
|
||||
// navigator.language.
|
||||
useLocaleStore.setState({ locale: 'fr' })
|
||||
})
|
||||
|
||||
const TREE: ZoneFindings = {
|
||||
id: 'sphenoid',
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
import { describe, it, expect, vi } from 'vitest'
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import VertebraPicker, {
|
||||
regionFromLabel,
|
||||
} from '@/components/observation/VertebraPicker'
|
||||
import { EQUINE_VERTEBRAL_FORMULA } from '@/domain/species/equine/vertebrae'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
|
||||
beforeEach(() => {
|
||||
useLocaleStore.setState({ locale: 'fr' })
|
||||
})
|
||||
|
||||
describe('VertebraPicker', () => {
|
||||
it('renders region tabs based on the formula', () => {
|
||||
|
||||
@@ -58,33 +58,32 @@ const baseReport: Report = {
|
||||
}
|
||||
|
||||
describe('buildZoneLabels', () => {
|
||||
it('maps detail-popup boneIds to their FR labels', async () => {
|
||||
it('maps detail-popup boneIds to their FR + EN labels', async () => {
|
||||
detailFetchShouldFail = false
|
||||
const labels = await buildZoneLabels(baseReport)
|
||||
// ATM hitbox in Horse_head.svg
|
||||
expect(labels.get('point-mpbyo7zq')).toBe(
|
||||
'Articulation Temporo-Mandibulaire (ATM)',
|
||||
)
|
||||
// Sphénoïde hitbox in Horse_head.svg
|
||||
expect(labels.get('point-mpbymcln')).toBe('Sphénoïde')
|
||||
const atm = labels.get('point-mpbyo7zq')
|
||||
expect(atm?.fr).toBe('Articulation Temporo-Mandibulaire (ATM)')
|
||||
expect(atm?.en).toBe('Temporomandibular Joint (TMJ)')
|
||||
const sphenoid = labels.get('point-mpbymcln')
|
||||
expect(sphenoid?.fr).toBe('Sphénoïde')
|
||||
expect(sphenoid?.en).toBe('Sphenoid')
|
||||
})
|
||||
|
||||
it('maps main-SVG boneIds to their FR labels', async () => {
|
||||
it('maps main-SVG boneIds to their FR + EN labels', async () => {
|
||||
detailFetchShouldFail = false
|
||||
const labels = await buildZoneLabels(baseReport)
|
||||
expect(labels.size).toBeGreaterThan(0)
|
||||
// The map should contain at least one Vertèbres entry from the main SVG.
|
||||
const values = Array.from(labels.values())
|
||||
expect(values.some((v) => v.includes('Vertèbres'))).toBe(true)
|
||||
const pairs = Array.from(labels.values())
|
||||
expect(pairs.some((p) => p.fr.includes('Vertèbres'))).toBe(true)
|
||||
expect(pairs.some((p) => p.en.includes('Vertebrae'))).toBe(true)
|
||||
})
|
||||
|
||||
it('keeps the main labels even when the detail SVG fetch fails', async () => {
|
||||
detailFetchShouldFail = true
|
||||
const labels = await buildZoneLabels(baseReport)
|
||||
// Detail entries gone — but main entries must survive the partial failure.
|
||||
expect(labels.get('point-mpbymcln')).toBeUndefined()
|
||||
const values = Array.from(labels.values())
|
||||
expect(values.some((v) => v.includes('Vertèbres'))).toBe(true)
|
||||
const pairs = Array.from(labels.values())
|
||||
expect(pairs.some((p) => p.fr.includes('Vertèbres'))).toBe(true)
|
||||
})
|
||||
|
||||
it('returns an empty map for an unknown species', async () => {
|
||||
|
||||
Reference in new issue
Block a user