4.6 KiB
applyTo
| applyTo |
|---|
| MainShell/Common/**/*.cs,**/*ViewModel.cs,**/*Service.cs,**/*Process*.cs |
Localization and Popup Instructions
Scope
These rules apply to internal program message dialogs only.
Do not apply these rules to:
- database alarms
- PLC alarm chain
- device alarm chain
- AlarmAsync main alarm path
中文说明
这些规则仅适用于程序内部提示弹窗。
不适用于:
- 数据库报警
- PLC 报警链路
- 设备报警主链路
AlarmAsync()等主报警链路
Required Popup Pattern
For internal prompts:
- define MessageKey enum value in
MainShell/Common/MessageKey.cs - add mapping in
LanguageResourceHelper.ResourceKeyMap - add Chinese resource in
MainShell/Language/MXJM_CN.xaml - add English resource in
MainShell/Language/MXJM_EN.xaml - call
LocalizedMessageBox.Show()orLocalizedMessageBox.ShowFormat()
中文说明
程序内提示弹窗开发流程:
- 在
MessageKey.cs中定义枚举 - 在
LanguageResourceHelper.ResourceKeyMap中增加映射 - 在
MXJM_CN.xaml中补中文资源 - 在
MXJM_EN.xaml中补英文资源 - 业务代码统一调用
LocalizedMessageBox.Show()或ShowFormat()
Required Title Keys
Use:
- MessageKey.TitleInfo
- MessageKey.TitleWarning
- MessageKey.TitleError
- MessageKey.TitleConfirm
中文说明
弹窗标题统一使用:
MessageKey.TitleInfoMessageKey.TitleWarningMessageKey.TitleErrorMessageKey.TitleConfirm
Formatting Rules
- For parameterized messages, use
ShowFormat() - Resource text should use placeholders such as
{0},{1}
中文说明
带参数的提示文案必须使用 ShowFormat(),资源文本使用 {0}、{1} 占位符。
Forbidden Patterns
Do not generate:
MwMessageBox.Show("中文")MessageBox.Show("中文")LocalizedMessageBox.Show("resourceKeyString")- direct resource dictionary access for popup text
中文说明
禁止生成以下写法:
MwMessageBox.Show("中文")MessageBox.Show("中文")LocalizedMessageBox.Show("资源key字符串")- 直接访问资源字典获取弹窗文案
Migration Rule
When modifying old internal prompt code, prefer migrating old MessageBox/MwMessageBox usage to LocalizedMessageBox and update:
- MessageKey enum
- ResourceKeyMap
- Chinese resource
- English resource
- business code call site
中文说明
迁移旧代码中的程序提示时,应优先改为 LocalizedMessageBox 方案,并同步补齐:
- MessageKey 枚举
- ResourceKeyMap 映射
- 中文资源
- 英文资源
- 业务代码调用点
Workflow / Process Error and Message Localization
Error messages, status messages, and user-facing messages generated in:
- Service layer (Service/*Service.cs)
- Activity layer (MainShell/Process/Activity/*.cs)
- ProcessService implementations
Must follow the same localization requirements as popup dialogs:
- Define MessageKey enum values for all error/status messages
- Register in LanguageResourceHelper.ResourceKeyMap
- Add translations in MXJM_CN.xaml and MXJM_EN.xaml
- Pass MessageKey enum (not raw strings) in WorkflowContext or result objects
- Display messages using LocalizedMessageBox from ViewModel/View layer
Do not hardcode error messages or status strings in Service/Activity code.
中文说明
在以下位置生成的错误信息、状态提示、用户提示:
- Service 层(Service/*Service.cs)
- Activity 层(MainShell/Process/Activity/*.cs)
- ProcessService 实现
必须遵循与弹窗相同的本地化规范:
- 在 MessageKey 中定义所有错误/状态消息的枚举值
- 在 LanguageResourceHelper.ResourceKeyMap 中注册
- 在 MXJM_CN.xaml 和 MXJM_EN.xaml 中添加对应翻译
- 在 WorkflowContext 或结果对象中传递 MessageKey 枚举值(不是原始字符串)
- 从 ViewModel/View 层使用 LocalizedMessageBox 显示消息
不允许在 Service/Activity 代码中硬编码错误信息或状态字符串。
Example: Adding Workflow Error Message
For a new workflow error in a Service:
-
Define in
MessageKey.cs:ProcessError_InvalidToolId, ProcessError_HardwareTimeout, -
Add to
LanguageResourceHelper.ResourceKeyMap:{ MessageKey.ProcessError_InvalidToolId, "MXJM:ProcessError_InvalidToolId" }, { MessageKey.ProcessError_HardwareTimeout, "MXJM:ProcessError_HardwareTimeout" }, -
In result object, return the message key:
public MessageKey? ErrorMessageKey { get; set; } -
In Activity's AfterExecute or ViewModel, check and display:
if (result.ErrorMessageKey.HasValue) { LocalizedMessageBox.Show(result.ErrorMessageKey.Value, MessageKey.TitleError); }
中文说明
以工作流错误为例:
-
在
MessageKey.cs中定义: ProcessError_InvalidToolId ProcessError_HardwareTimeout -
在
LanguageResourceHelper.ResourceKeyMap中注册 -
在 Service 返回对象中包含 MessageKey
-
在 Activity AfterExecute 或 ViewModel 中检查并使用 LocalizedMessageBox 显示