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
@@ -2,6 +2,7 @@ import { useEffect, useRef, useState } from 'react'
|
||||
import { loadSvg } from '@/anatomy/svgLoader'
|
||||
import { getBoneIdFromEvent } from '@/anatomy/svgConvention'
|
||||
import type { BoneState } from '@/anatomy/types'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
|
||||
export interface AnatomyCanvasProps {
|
||||
src: string
|
||||
@@ -18,6 +19,7 @@ export default function AnatomyCanvas({
|
||||
}: AnatomyCanvasProps) {
|
||||
const containerRef = useRef<HTMLDivElement | null>(null)
|
||||
const [loadedSrc, setLoadedSrc] = useState<string | null>(null)
|
||||
const locale = useLocaleStore((s) => s.locale)
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false
|
||||
@@ -56,6 +58,33 @@ export default function AnatomyCanvas({
|
||||
})
|
||||
}, [boneStates, loadedSrc, src])
|
||||
|
||||
// Rewrite native SVG <title> tooltips to match the active locale. The
|
||||
// upstream SVG ships titles as "FR / EN" concatenations; we replace the
|
||||
// text content with just the locale-relevant label so the browser-native
|
||||
// hover tooltip stays in sync with the rest of the UI. The detail-popup
|
||||
// hint ("🔍 Zoom: head") is left intact since it carries an emoji affordance,
|
||||
// not a translatable label.
|
||||
useEffect(() => {
|
||||
const c = containerRef.current
|
||||
if (!c || loadedSrc !== src) return
|
||||
const annotated = c.querySelectorAll<Element>('[data-anno-id]')
|
||||
annotated.forEach((el) => {
|
||||
if (el.hasAttribute('data-anno-opens-detail')) return
|
||||
const fr = el.getAttribute('data-anno-name-fr') ?? ''
|
||||
const en = el.getAttribute('data-anno-name-en') ?? ''
|
||||
const preferred = locale === 'en' ? en || fr : fr || en
|
||||
if (!preferred) return
|
||||
let titleEl = el.querySelector(':scope > title')
|
||||
if (!titleEl) {
|
||||
const doc = el.ownerDocument
|
||||
if (!doc) return
|
||||
titleEl = doc.createElementNS('http://www.w3.org/2000/svg', 'title')
|
||||
el.insertBefore(titleEl, el.firstChild)
|
||||
}
|
||||
titleEl.textContent = preferred
|
||||
})
|
||||
}, [locale, loadedSrc, src])
|
||||
|
||||
return (
|
||||
<div
|
||||
data-testid="anatomy-canvas"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import Dialog from '@/components/ui/Dialog'
|
||||
import AnatomyCanvas from './AnatomyCanvas'
|
||||
import type { BoneState } from '@/anatomy/types'
|
||||
import { useT } from '@/i18n/useT'
|
||||
|
||||
export interface DetailModalProps {
|
||||
open: boolean
|
||||
@@ -21,6 +22,7 @@ export default function DetailModal({
|
||||
boneStates,
|
||||
onZoneClick,
|
||||
}: DetailModalProps) {
|
||||
const t = useT()
|
||||
return (
|
||||
<Dialog open={open} onClose={onClose} title={title} size="xl">
|
||||
<div className="aspect-[4/3] w-full">
|
||||
@@ -31,7 +33,7 @@ export default function DetailModal({
|
||||
/>
|
||||
</div>
|
||||
<p className="mt-4 text-sm text-[var(--color-ink-muted)]">
|
||||
Cliquez sur les zones pour les ajouter à l'observation en cours.
|
||||
{t('detail.click_to_add')}
|
||||
</p>
|
||||
</Dialog>
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user