From 15ae5e087338bab90fb4677368436c014bd4c55c Mon Sep 17 00:00:00 2001 From: Rainer Killinger Date: Mon, 28 Sep 2020 16:36:33 +0200 Subject: [PATCH] refactor: remove narrow property value translation --- src/translator.ts | 36 ++---------------------------------- 1 file changed, 2 insertions(+), 34 deletions(-) diff --git a/src/translator.ts b/src/translator.ts index 6c394040..becb0096 100644 --- a/src/translator.ts +++ b/src/translator.ts @@ -244,41 +244,9 @@ export class SCThingTranslator { field: string, key?: string, language?: keyof SCTranslations): 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(type: SCThingType, - language?: keyof SCTranslations): 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; } /**