Add behavior intern i18n system

This commit is contained in:
2022-03-29 10:57:28 +08:00
parent 791b554ca0
commit b6f8828c3b
8 changed files with 71 additions and 17 deletions
+26
View File
@@ -132,6 +132,8 @@ type IBehaviorConstructor<
type IAnyBehavior = Behavior<any, any>;
type IAnyBehaviorRecorder = BehaviorRecorder<any, any>;
type Language = "ZH_CN" | "EN_US";
/**
* 行为的基础信息
*/
@@ -156,6 +158,29 @@ class BehaviorInfo<E extends Record<EventType, any> = {}> extends Emitter<E> {
* 行为描述
*/
public describe: string = "";
/**
* 提条列表
*/
public terms: Record<string, Record<Language | string, string>> = {};
/**
* 获取词条翻译
*/
public getTerms(key: string, language?: Language | string): string {
if (key[0] === "$" && this.terms[key]) {
let res: string = "";
if (language) {
res = this.terms[key][language];
} else {
res = this.terms[key]["EN_US"];
}
if (res) {
return res;
}
}
return key;
}
}
class BehaviorRecorder<
@@ -239,6 +264,7 @@ class BehaviorRecorder<
this.behaviorId = this.behaviorInstance.behaviorId;
this.behaviorName = this.behaviorInstance.behaviorName;
this.describe = this.behaviorInstance.describe;
this.terms = this.behaviorInstance.terms;
}
}