mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-09 19:22:51 +00:00
feat: extend property value translation retrival
This commit is contained in:
@@ -229,6 +229,38 @@ export class SCThingTranslator {
|
||||
return this.getAllMetaFieldTranslations(type, targetLanguage) as T;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a SCThingType and a corresponding property name it returns the known property value translation
|
||||
* Access pattern to the meta object containing the translation can be thought of as type.field[key] with key being optional
|
||||
* @example
|
||||
* const translatedMetaDish = translator.translatedPropertyNames(SCThingType.Dish, 'categories', 'main dish');
|
||||
* @param type The type for whose property values a translation is required
|
||||
* @param field The property for which a translation is required
|
||||
* @param key If specified tries to access the field with this key
|
||||
* @param language The language all property names will be translated to
|
||||
* @returns Known translation for the property
|
||||
*/
|
||||
public translatedPropertyValue<T extends unknown>(type: SCThingType,
|
||||
field: string,
|
||||
key?: string,
|
||||
language?: keyof SCTranslations<T>): string | undefined {
|
||||
const targetLanguage = (typeof language !== 'undefined') ? language : this.language;
|
||||
const metaClass = this.getMetaClassInstance(type);
|
||||
|
||||
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
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user