mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-10 19:52:53 +00:00
refactor: remove narrow property value translation
This commit is contained in:
@@ -244,41 +244,9 @@ export class SCThingTranslator {
|
|||||||
field: string,
|
field: string,
|
||||||
key?: string,
|
key?: string,
|
||||||
language?: keyof SCTranslations<T>): string | undefined {
|
language?: keyof SCTranslations<T>): string | undefined {
|
||||||
const targetLanguage = (typeof language !== 'undefined') ? language : this.language;
|
const fieldTranslation = this.getMetaClassInstance(type).fieldValueTranslations[language ?? this.language]?.[field];
|
||||||
const metaClass = this.getMetaClassInstance(type);
|
|
||||||
|
|
||||||
if (typeof metaClass.fieldValueTranslations[targetLanguage] !== 'undefined' &&
|
return fieldTranslation?.[key ?? ''] ?? fieldTranslation ?? key;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user