refactor: remove narrow property value translation

This commit is contained in:
Rainer Killinger
2020-09-28 16:36:33 +02:00
parent a246bdea84
commit 15ae5e0873

View File

@@ -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;
}
/**