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