mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-08 06:22:53 +00:00
refactor: remove narrow property value translation
This commit is contained in:
@@ -244,41 +244,9 @@ export class SCThingTranslator {
|
||||
field: string,
|
||||
key?: string,
|
||||
language?: keyof SCTranslations<T>): string | undefined {
|
||||
const targetLanguage = (typeof language !== 'undefined') ? language : this.language;
|
||||
const metaClass = this.getMetaClassInstance(type);
|
||||
const fieldTranslation = this.getMetaClassInstance(type).fieldValueTranslations[language ?? this.language]?.[field];
|
||||
|
||||
if (typeof metaClass.fieldValueTranslations[targetLanguage] !== 'undefined' &&
|
||||
typeof metaClass.fieldValueTranslations[targetLanguage][field] !== 'undefined') {
|
||||
if (typeof key === 'string' &&
|
||||
typeof metaClass.fieldValueTranslations[targetLanguage][field][key] !== 'undefined') {
|
||||
|
||||
return metaClass.fieldValueTranslations[targetLanguage][field][key] as string ;
|
||||
}
|
||||
|
||||
return metaClass.fieldValueTranslations[targetLanguage][field] as string ;
|
||||
}
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a SCThingType this function will translate it
|
||||
*
|
||||
* @param type The type that will be translated
|
||||
* @param language The language the type will be translated to
|
||||
* @returns Known translation of type parameter
|
||||
*/
|
||||
public translatedThingType<T extends unknown>(type: SCThingType,
|
||||
language?: keyof SCTranslations<T>): string {
|
||||
const targetLanguage = (typeof language !== 'undefined') ? language : this.language;
|
||||
const metaClass = this.getMetaClassInstance(type);
|
||||
|
||||
if (typeof metaClass.fieldValueTranslations[targetLanguage] !== 'undefined' &&
|
||||
typeof metaClass.fieldValueTranslations[targetLanguage].type !== 'undefined') {
|
||||
return metaClass.fieldValueTranslations[targetLanguage].type as string ;
|
||||
}
|
||||
|
||||
return type;
|
||||
return fieldTranslation?.[key ?? ''] ?? fieldTranslation ?? key;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user