feat: add function to get translated SCThingType

This commit is contained in:
Rainer Killinger
2020-06-15 16:12:13 +02:00
parent 907d61b5d2
commit fe7f1a53ae

View File

@@ -229,6 +229,26 @@ export class SCThingTranslator {
return this.getAllMetaFieldTranslations(type, targetLanguage) as T;
}
/**
* 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;
}
/**
* Recursively translates the given object in-place
* Translated values overwrite current values (destructive)