feat(species): locale-aware species labels via labelEn

B-6: SpeciesManifest only carried labelFr — EN users saw 'Cheval'.
labelEn required on the manifest, speciesLabel(s, locale) helper in
registry; AnimalForm dropdown + SvgEditor picker localized (locale
passed into initSvgEditor, re-inits on locale change). Scaffolder
template + ADDING-A-SPECIES.md + registry test updated.
This commit is contained in:
Bastien Chanot committed 2026-07-12 16:23:07 +02:00
1 parent 74e1623135
commit b047d352c1
8 files changed
+30 -12

No files matched your search

+8 -6
View File
@@ -4,7 +4,8 @@ import AppHeader from '@/components/brand/AppHeader'
import { useT } from '@/i18n/useT'
import { useLocaleStore } from '@/state/localeStore'
import { getDict } from '@/i18n/index'
import { getAllSpecies } from '@/domain/species/registry'
import type { Locale } from '@/i18n/types'
import { getAllSpecies, speciesLabel } from '@/domain/species/registry'
import '@/styles/svg-editor.css'
type TFn = (key: string) => string
@@ -35,7 +36,7 @@ export default function SvgEditorRoute() {
const dict = getDict(locale)
const tFn: TFn = (key: string) => dict[key] ?? key
const cleanup = initSvgEditor(canvas, canvasInner, sidebar, tFn)
const cleanup = initSvgEditor(canvas, canvasInner, sidebar, tFn, locale)
cleanupRef.current = cleanup
return () => {
@@ -248,6 +249,7 @@ function initSvgEditor(
canvasInner: HTMLDivElement,
_sidebar: HTMLDivElement,
t: TFn,
locale: Locale,
): () => void {
const ac = new AbortController()
const sig = { signal: ac.signal }
@@ -401,13 +403,13 @@ function initSvgEditor(
}
function buildProjectPicker(container: HTMLElement) {
const speciesLabel = document.createElement('label')
speciesLabel.textContent = t('svg_editor.species')
const speciesLabelEl = document.createElement('label')
speciesLabelEl.textContent = t('svg_editor.species')
const speciesSel = document.createElement('select')
speciesList.forEach((sp) => {
const opt = document.createElement('option')
opt.value = sp.id
opt.textContent = sp.labelFr
opt.textContent = speciesLabel(sp, locale)
speciesSel.appendChild(opt)
})
@@ -459,7 +461,7 @@ function initSvgEditor(
})
})
container.append(speciesLabel, speciesSel, viewLabel, viewSel, loadBtn)
container.append(speciesLabelEl, speciesSel, viewLabel, viewSel, loadBtn)
}
function buildUploadPicker(container: HTMLElement) {
+4 -2
View File
@@ -2,8 +2,9 @@ import type { Animal, Owner } from '@/domain/schema/animal'
import Label from '@/components/ui/Label'
import Input from '@/components/ui/Input'
import Select from '@/components/ui/Select'
import { getAllSpecies } from '@/domain/species/registry'
import { getAllSpecies, speciesLabel } from '@/domain/species/registry'
import { useT } from '@/i18n/useT'
import { useLocaleStore } from '@/state/localeStore'
export interface AnimalFormProps {
animal: Animal
@@ -14,6 +15,7 @@ export interface AnimalFormProps {
export default function AnimalForm({ animal, owner, onChangeAnimal, onChangeOwner }: AnimalFormProps) {
const t = useT()
const locale = useLocaleStore((s) => s.locale)
const species = getAllSpecies()
const setA = (patch: Partial<Animal>) => onChangeAnimal({ ...animal, ...patch })
return (
@@ -29,7 +31,7 @@ export default function AnimalForm({ animal, owner, onChangeAnimal, onChangeOwne
onChange={(e) => setA({ speciesId: e.target.value })}
>
{species.map((s) => (
<option key={s.id} value={s.id}>{s.labelFr}</option>
<option key={s.id} value={s.id}>{speciesLabel(s, locale)}</option>
))}
</Select>
</div>
+1
View File
@@ -4,6 +4,7 @@ import { EQUINE_VERTEBRAL_FORMULA } from './vertebrae'
const equine: SpeciesManifest = {
id: 'equine',
labelFr: 'Cheval',
labelEn: 'Horse',
mainSvg: '/species/equine/Horse.svg',
details: {
head: '/species/equine/Horse_head.svg',
+6
View File
@@ -1,4 +1,5 @@
import type { SpeciesManifest } from './types'
import type { Locale } from '@/i18n/types'
/**
* Auto-discovers every species manifest in `src/domain/species/*\/index.ts`
@@ -49,3 +50,8 @@ export function getAllSpecies(): SpeciesManifest[] {
a.labelFr.localeCompare(b.labelFr, 'fr'),
)
}
/** Display label of a species for the given locale. */
export function speciesLabel(s: SpeciesManifest, locale: Locale): string {
return locale === 'en' ? s.labelEn : s.labelFr
}
+2
View File
@@ -17,6 +17,8 @@ export interface SpeciesManifest {
id: string
/** Display name in French */
labelFr: string
/** Display name in English */
labelEn: string
/** Absolute public path to the main anatomy SVG */
mainSvg: string
/**