diff --git a/source/Behavior/Template.ts b/source/Behavior/Template.ts index ff3a17a..fca9fd2 100644 --- a/source/Behavior/Template.ts +++ b/source/Behavior/Template.ts @@ -10,11 +10,22 @@ class Template extends Behavior> = { + "$Title": { + "ZH_CN": "行为", + "EN_US": "Behavior" + }, + "$Intro": { + "ZH_CN": "这是一个模板行为", + "EN_US": "This is a template behavior" + } + }; } export { Template }; \ No newline at end of file diff --git a/source/Component/BehaviorList/BehaviorList.tsx b/source/Component/BehaviorList/BehaviorList.tsx index ce91bb9..00e6081 100644 --- a/source/Component/BehaviorList/BehaviorList.tsx +++ b/source/Component/BehaviorList/BehaviorList.tsx @@ -1,8 +1,8 @@ import { Theme } from "@Component/Theme/Theme"; import { Component, ReactNode } from "react"; import { IRenderBehavior, Behavior, BehaviorRecorder } from "@Model/Behavior"; +import { useSettingWithEvent, IMixinSettingProps } from "@Context/Setting"; import { Icon } from "@fluentui/react"; -import { Localization } from "@Component/Localization/Localization"; import "./BehaviorList.scss"; interface IBehaviorListProps { @@ -13,7 +13,8 @@ interface IBehaviorListProps { actionType?: "info" | "delete"; } -class BehaviorList extends Component { +@useSettingWithEvent("language") +class BehaviorList extends Component { private isFocus(behavior: IRenderBehavior): boolean { if (this.props.focusBehaviors) { @@ -57,10 +58,10 @@ class BehaviorList extends Component { } - private renderTerm(key: string, className: string, needLocal: boolean) { + private renderTerm(behavior: IRenderBehavior, key: string, className: string, needLocal: boolean) { if (needLocal) { return
- + {behavior.getTerms(key, this.props.setting?.language)}
; } else { return
@@ -117,8 +118,8 @@ class BehaviorList extends Component {
- {this.renderTerm(name, "title-view", needLocal)} - {this.renderTerm(info, "info-view", needLocal)} + {this.renderTerm(behavior, name, "title-view", needLocal)} + {this.renderTerm(behavior, info, "info-view", needLocal)}
{this.renderActionButton(behavior)} diff --git a/source/Component/BehaviorPopup/BehaviorPopup.tsx b/source/Component/BehaviorPopup/BehaviorPopup.tsx index b87154c..5c813e1 100644 --- a/source/Component/BehaviorPopup/BehaviorPopup.tsx +++ b/source/Component/BehaviorPopup/BehaviorPopup.tsx @@ -66,10 +66,14 @@ class BehaviorPopupComponent extends Component< if (this.props.status) { const status = this.props.status; status.popup.showPopup(ConfirmPopup, { - infoI18n: behavior.describe as any, + renderInfo: () => { + return + }, titleI18N: "Popup.Behavior.Info.Title", titleI18NOption: { - behavior: I18N(this.props, behavior.behaviorName as any) + behavior: behavior.getTerms(behavior.behaviorName, this.props.setting?.language) }, yesI18n: "Popup.Behavior.Info.Confirm", }) diff --git a/source/Component/ConfirmPopup/ConfirmPopup.tsx b/source/Component/ConfirmPopup/ConfirmPopup.tsx index 0fad186..fe75de2 100644 --- a/source/Component/ConfirmPopup/ConfirmPopup.tsx +++ b/source/Component/ConfirmPopup/ConfirmPopup.tsx @@ -11,6 +11,7 @@ interface IConfirmPopupProps { infoI18n?: AllI18nKeys; yesI18n?: AllI18nKeys; noI18n?: AllI18nKeys; + renderInfo?: () => ReactNode; red?: "yes" | "no"; yes?: () => any; no?: () => any; @@ -59,7 +60,13 @@ class ConfirmPopup extends Popup { return - {this.props.infoI18n ? : null} + { + this.props.renderInfo ? + this.props.renderInfo() : + this.props.infoI18n ? + : + null + } } } diff --git a/source/Component/Message/Message.tsx b/source/Component/Message/Message.tsx index d46f997..56384da 100644 --- a/source/Component/Message/Message.tsx +++ b/source/Component/Message/Message.tsx @@ -4,7 +4,8 @@ import { FunctionComponent } from "react"; import "./Message.scss"; interface IMessageProps { - i18nKey: AllI18nKeys; + i18nKey?: AllI18nKeys; + text?: string; options?: Record; className?: string; isTitle?: boolean; @@ -34,7 +35,15 @@ const MessageView: FunctionComponent = (prop } return
- {I18N(language, props.i18nKey, props.options)} + { + props.text ? + {props.text} : + props.i18nKey ? + { + I18N(language, props.i18nKey, props.options) + } : + null + }
} diff --git a/source/Localization/EN-US.ts b/source/Localization/EN-US.ts index 124c4f1..81ef619 100644 --- a/source/Localization/EN-US.ts +++ b/source/Localization/EN-US.ts @@ -59,8 +59,6 @@ const EN_US = { "Popup.Behavior.Info.Confirm": "OK, I know it", "Build.In.Label.Name.All.Group": "All group", "Build.In.Label.Name.All.Range": "All range", - "Behavior.Template.Title": "Behavior", - "Behavior.Template.Intro": "This is a template behavior", "Common.Search.Placeholder": "Search in here...", "Common.No.Data": "No Data", "Common.No.Unknown.Error": "Unknown error", diff --git a/source/Localization/ZH-CN.ts b/source/Localization/ZH-CN.ts index 3495892..7fe2ba6 100644 --- a/source/Localization/ZH-CN.ts +++ b/source/Localization/ZH-CN.ts @@ -59,8 +59,6 @@ const ZH_CN = { "Popup.Behavior.Info.Confirm": "好的, 我知道了", "Build.In.Label.Name.All.Group": "全部群", "Build.In.Label.Name.All.Range": "全部范围", - "Behavior.Template.Title": "行为", - "Behavior.Template.Intro": "这是一个模板行为", "Common.Search.Placeholder": "在此处搜索...", "Common.No.Data": "暂无数据", "Common.No.Unknown.Error": "未知错误", diff --git a/source/Model/Behavior.ts b/source/Model/Behavior.ts index ff8abf9..3d664fd 100644 --- a/source/Model/Behavior.ts +++ b/source/Model/Behavior.ts @@ -132,6 +132,8 @@ type IBehaviorConstructor< type IAnyBehavior = Behavior; type IAnyBehaviorRecorder = BehaviorRecorder; +type Language = "ZH_CN" | "EN_US"; + /** * 行为的基础信息 */ @@ -156,6 +158,29 @@ class BehaviorInfo = {}> extends Emitter { * 行为描述 */ public describe: string = ""; + + /** + * 提条列表 + */ + public terms: Record> = {}; + + /** + * 获取词条翻译 + */ + 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; } }