22 lines
516 B
TypeScript
22 lines
516 B
TypeScript
export function getLocalizedField(field: any, currentLang: string): string {
|
|
if (field === null || field === undefined) {
|
|
return '';
|
|
}
|
|
if (typeof field === 'string') {
|
|
return field;
|
|
}
|
|
if (typeof field === 'object') {
|
|
if (field[currentLang] !== undefined) {
|
|
return field[currentLang];
|
|
}
|
|
if (field['en'] !== undefined) {
|
|
return field['en'];
|
|
}
|
|
const keys = Object.keys(field);
|
|
if (keys.length > 0) {
|
|
return field[keys[0]];
|
|
}
|
|
}
|
|
return String(field);
|
|
}
|