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

+2 -1
View File
@@ -113,9 +113,10 @@ files by absolute path starting with `/species/...`.
import type { SpeciesManifest } from '@/domain/species/types' import type { SpeciesManifest } from '@/domain/species/types'
import { CANINE_VERTEBRAL_FORMULA } from './vertebrae' import { CANINE_VERTEBRAL_FORMULA } from './vertebrae'
export const canine: SpeciesManifest = { const canine: SpeciesManifest = {
id: 'canine', id: 'canine',
labelFr: 'Chien', labelFr: 'Chien',
labelEn: 'Dog',
mainSvg: '/species/canine/Dog.svg', mainSvg: '/species/canine/Dog.svg',
details: { details: {
head: '/species/canine/Dog_head.svg', head: '/species/canine/Dog_head.svg',
+6 -3
View File
@@ -65,16 +65,17 @@ function capitalize(s) {
return s.charAt(0).toUpperCase() + s.slice(1) return s.charAt(0).toUpperCase() + s.slice(1)
} }
function indexTs({ id, labelFr, mainSvgPath, details, formulaConstName }) { function indexTs({ id, labelFr, labelEn, mainSvgPath, details, formulaConstName }) {
const detailLines = details const detailLines = details
.map((d) => ` ${d.key}: '${d.path}',`) .map((d) => ` ${d.key}: '${d.path}',`)
.join('\n') .join('\n')
return `import type { SpeciesManifest } from '@/domain/species/types' return `import type { SpeciesManifest } from '@/domain/species/types'
import { ${formulaConstName} } from './vertebrae' import { ${formulaConstName} } from './vertebrae'
export const ${id}: SpeciesManifest = { const ${id}: SpeciesManifest = {
id: '${id}', id: '${id}',
labelFr: '${labelFr.replace(/'/g, "\\'")}', labelFr: '${labelFr.replace(/'/g, "\\'")}',
labelEn: '${labelEn.replace(/'/g, "\\'")}',
mainSvg: '${mainSvgPath}', mainSvg: '${mainSvgPath}',
details: { details: {
${detailLines} ${detailLines}
@@ -83,6 +84,8 @@ ${detailLines}
findings: () => import('./pathologies'), findings: () => import('./pathologies'),
} }
// Default export is the convention picked up by the registry's
// import.meta.glob() auto-discovery.
export default ${id} export default ${id}
` `
} }
@@ -184,7 +187,7 @@ async function main() {
const formulaConstName = `${id.replace(/-/g, '_').toUpperCase()}_VERTEBRAL_FORMULA` const formulaConstName = `${id.replace(/-/g, '_').toUpperCase()}_VERTEBRAL_FORMULA`
const speciesDir = resolve(PROJECT_ROOT, 'src/domain/species', id) const speciesDir = resolve(PROJECT_ROOT, 'src/domain/species', id)
const targets = { const targets = {
'index.ts': indexTs({ id, labelFr, mainSvgPath, details, formulaConstName }), 'index.ts': indexTs({ id, labelFr, labelEn, mainSvgPath, details, formulaConstName }),
'vertebrae.ts': vertebraeTs({ formulaConstName, labelFr, formula }), 'vertebrae.ts': vertebraeTs({ formulaConstName, labelFr, formula }),
'pathologies.ts': pathologiesTs(), 'pathologies.ts': pathologiesTs(),
'pathologies.json': pathologiesJsonTemplate({ id, labelFr, labelEn }), 'pathologies.json': pathologiesJsonTemplate({ id, labelFr, labelEn }),
+8 -6
View File
@@ -4,7 +4,8 @@ import AppHeader from '@/components/brand/AppHeader'
import { useT } from '@/i18n/useT' import { useT } from '@/i18n/useT'
import { useLocaleStore } from '@/state/localeStore' import { useLocaleStore } from '@/state/localeStore'
import { getDict } from '@/i18n/index' 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' import '@/styles/svg-editor.css'
type TFn = (key: string) => string type TFn = (key: string) => string
@@ -35,7 +36,7 @@ export default function SvgEditorRoute() {
const dict = getDict(locale) const dict = getDict(locale)
const tFn: TFn = (key: string) => dict[key] ?? key 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 cleanupRef.current = cleanup
return () => { return () => {
@@ -248,6 +249,7 @@ function initSvgEditor(
canvasInner: HTMLDivElement, canvasInner: HTMLDivElement,
_sidebar: HTMLDivElement, _sidebar: HTMLDivElement,
t: TFn, t: TFn,
locale: Locale,
): () => void { ): () => void {
const ac = new AbortController() const ac = new AbortController()
const sig = { signal: ac.signal } const sig = { signal: ac.signal }
@@ -401,13 +403,13 @@ function initSvgEditor(
} }
function buildProjectPicker(container: HTMLElement) { function buildProjectPicker(container: HTMLElement) {
const speciesLabel = document.createElement('label') const speciesLabelEl = document.createElement('label')
speciesLabel.textContent = t('svg_editor.species') speciesLabelEl.textContent = t('svg_editor.species')
const speciesSel = document.createElement('select') const speciesSel = document.createElement('select')
speciesList.forEach((sp) => { speciesList.forEach((sp) => {
const opt = document.createElement('option') const opt = document.createElement('option')
opt.value = sp.id opt.value = sp.id
opt.textContent = sp.labelFr opt.textContent = speciesLabel(sp, locale)
speciesSel.appendChild(opt) 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) { 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 Label from '@/components/ui/Label'
import Input from '@/components/ui/Input' import Input from '@/components/ui/Input'
import Select from '@/components/ui/Select' 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 { useT } from '@/i18n/useT'
import { useLocaleStore } from '@/state/localeStore'
export interface AnimalFormProps { export interface AnimalFormProps {
animal: Animal animal: Animal
@@ -14,6 +15,7 @@ export interface AnimalFormProps {
export default function AnimalForm({ animal, owner, onChangeAnimal, onChangeOwner }: AnimalFormProps) { export default function AnimalForm({ animal, owner, onChangeAnimal, onChangeOwner }: AnimalFormProps) {
const t = useT() const t = useT()
const locale = useLocaleStore((s) => s.locale)
const species = getAllSpecies() const species = getAllSpecies()
const setA = (patch: Partial<Animal>) => onChangeAnimal({ ...animal, ...patch }) const setA = (patch: Partial<Animal>) => onChangeAnimal({ ...animal, ...patch })
return ( return (
@@ -29,7 +31,7 @@ export default function AnimalForm({ animal, owner, onChangeAnimal, onChangeOwne
onChange={(e) => setA({ speciesId: e.target.value })} onChange={(e) => setA({ speciesId: e.target.value })}
> >
{species.map((s) => ( {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> </Select>
</div> </div>
+1
View File
@@ -4,6 +4,7 @@ import { EQUINE_VERTEBRAL_FORMULA } from './vertebrae'
const equine: SpeciesManifest = { const equine: SpeciesManifest = {
id: 'equine', id: 'equine',
labelFr: 'Cheval', labelFr: 'Cheval',
labelEn: 'Horse',
mainSvg: '/species/equine/Horse.svg', mainSvg: '/species/equine/Horse.svg',
details: { details: {
head: '/species/equine/Horse_head.svg', head: '/species/equine/Horse_head.svg',
+6
View File
@@ -1,4 +1,5 @@
import type { SpeciesManifest } from './types' import type { SpeciesManifest } from './types'
import type { Locale } from '@/i18n/types'
/** /**
* Auto-discovers every species manifest in `src/domain/species/*\/index.ts` * 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'), 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 id: string
/** Display name in French */ /** Display name in French */
labelFr: string labelFr: string
/** Display name in English */
labelEn: string
/** Absolute public path to the main anatomy SVG */ /** Absolute public path to the main anatomy SVG */
mainSvg: string mainSvg: string
/** /**
+1
View File
@@ -6,6 +6,7 @@ describe('species registry', () => {
const eq = getSpecies('equine') const eq = getSpecies('equine')
expect(eq).toBeDefined() expect(eq).toBeDefined()
expect(eq?.labelFr).toBe('Cheval') expect(eq?.labelFr).toBe('Cheval')
expect(eq?.labelEn).toBe('Horse')
expect(eq?.mainSvg).toBe('/species/equine/Horse.svg') expect(eq?.mainSvg).toBe('/species/equine/Horse.svg')
expect(eq?.details.head).toBe('/species/equine/Horse_head.svg') expect(eq?.details.head).toBe('/species/equine/Horse_head.svg')
expect(eq?.vertebralFormula).toEqual({ C: 7, T: 18, L: 6, S: 5, Cd: 18 }) expect(eq?.vertebralFormula).toEqual({ C: 7, T: 18, L: 6, S: 5, Cd: 18 })