chore(i18n): extract shared pickLocaleLabel helper
This commit is contained in:
1 parent
d7c9d39b13
commit
a5849113e5
4 files changed
+22
-6
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import type { Locale } from '@/i18n/types'
|
||||
import { pickLocaleLabel } from '@/i18n/pickLocaleLabel'
|
||||
import type { Bone } from './types'
|
||||
|
||||
/**
|
||||
@@ -14,6 +15,5 @@ export function boneLabel(
|
||||
fallback: string,
|
||||
): string {
|
||||
if (!bone) return fallback
|
||||
if (locale === 'en') return bone.en || bone.fr || fallback
|
||||
return bone.fr || bone.en || fallback
|
||||
return pickLocaleLabel(bone.fr, bone.en, locale, fallback)
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
} from '@/anatomy/svgConvention'
|
||||
import type { BoneState } from '@/anatomy/types'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { pickLocaleLabel } from '@/i18n/pickLocaleLabel'
|
||||
|
||||
export interface AnatomyCanvasProps {
|
||||
src: string
|
||||
@@ -69,7 +70,7 @@ export default function AnatomyCanvas({
|
||||
if (!tip) return
|
||||
const fr = el.getAttribute('data-anno-name-fr') ?? ''
|
||||
const en = el.getAttribute('data-anno-name-en') ?? ''
|
||||
const label = locale === 'en' ? en || fr : fr || en
|
||||
const label = pickLocaleLabel(fr, en, locale)
|
||||
if (!label) { tip.style.opacity = '0'; return }
|
||||
tip.textContent = label
|
||||
tip.style.opacity = '1'
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import type { Locale } from './types'
|
||||
|
||||
/**
|
||||
* Resolves a bilingual label for the active locale. Falls back to the
|
||||
* opposite language when the preferred one is missing/empty, then to the
|
||||
* provided fallback, so callers never render an empty string.
|
||||
*/
|
||||
export function pickLocaleLabel(
|
||||
fr: string | undefined,
|
||||
en: string | undefined,
|
||||
locale: Locale,
|
||||
fallback = '',
|
||||
): string {
|
||||
if (locale === 'en') return en || fr || fallback
|
||||
return fr || en || fallback
|
||||
}
|
||||
@@ -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 { pickLocaleLabel } from '@/i18n/pickLocaleLabel'
|
||||
import type { ZoneLabelPair } from '@/pdf/export'
|
||||
import { drawHeader, type HeaderAssets } from './header'
|
||||
import { rasterizeSvg } from './svgToPng'
|
||||
@@ -353,9 +354,7 @@ export async function addObservationPage(
|
||||
const zonesText = observation.zones
|
||||
.map((z) => {
|
||||
const pair = zoneLabels.get(z.boneId)
|
||||
const label = pair
|
||||
? (locale === 'en' ? pair.en || pair.fr : pair.fr || pair.en) || z.boneId
|
||||
: z.boneId
|
||||
const label = pickLocaleLabel(pair?.fr, pair?.en, locale, z.boneId)
|
||||
const v = z.vertebrae?.length
|
||||
? ` (${z.vertebrae.map((x) => `${x.region}${x.index}`).join(', ')})`
|
||||
: ''
|
||||
|
||||
Reference in new issue
Block a user