diff --git a/src/translator.ts b/src/translator.ts index 2e86e9f2..abbdf555 100644 --- a/src/translator.ts +++ b/src/translator.ts @@ -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(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; + } + /** * Recursively translates the given object in-place * Translated values overwrite current values (destructive)