integration new apis

This commit is contained in:
sdarbinyan
2026-03-24 00:09:11 +04:00
parent 3445f55758
commit 56f4c56b9e
47 changed files with 2603 additions and 1577 deletions

View File

@@ -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 '';