integration new apis
This commit is contained in:
@@ -61,17 +61,31 @@ export function getBadgeClass(badge: string): string {
|
||||
|
||||
/**
|
||||
* Get the translated name/description for the current language.
|
||||
* Falls back to the default (base) field if no translation exists.
|
||||
* Checks translations map first, then names[]/descriptions[] arrays,
|
||||
* then falls back to the default (base) field.
|
||||
*/
|
||||
export function getTranslatedField(
|
||||
item: Item,
|
||||
field: 'name' | 'simpleDescription',
|
||||
lang: string
|
||||
): string {
|
||||
// 1. Check translations map (backOffice format)
|
||||
const translation = item.translations?.[lang];
|
||||
if (translation && translation[field]) {
|
||||
return translation[field]!;
|
||||
}
|
||||
|
||||
// 2. Check names[]/descriptions[] arrays (backend API format)
|
||||
if (field === 'name' && item.names?.length) {
|
||||
const entry = item.names.find(n => n.language === lang);
|
||||
if (entry) return entry.value;
|
||||
}
|
||||
if (field === 'simpleDescription' && item.descriptions?.length) {
|
||||
const entry = item.descriptions.find(d => d.language === lang);
|
||||
if (entry) return entry.value;
|
||||
}
|
||||
|
||||
// 3. Fallback to base field
|
||||
if (field === 'name') return item.name;
|
||||
if (field === 'simpleDescription') return item.simpleDescription || item.description || '';
|
||||
return '';
|
||||
|
||||
Reference in New Issue
Block a user