Files
test_demo/MX-PD-盘古 - new/PanGu.DieBonderApp/.github/instructions/localization-popup.instructions.md
Shi.Ji e31d3560bb 添加 MX-PD-盘古 项目文件
将 MX-PD-盘古 - new 目录下的所有文件添加到主仓库
2026-05-18 11:43:09 +08:00

162 lines
4.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
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:
1. define MessageKey enum value in `MainShell/Common/MessageKey.cs`
2. add mapping in `LanguageResourceHelper.ResourceKeyMap`
3. add Chinese resource in `MainShell/Language/MXJM_CN.xaml`
4. add English resource in `MainShell/Language/MXJM_EN.xaml`
5. call `LocalizedMessageBox.Show()` or `LocalizedMessageBox.ShowFormat()`
## 中文说明
程序内提示弹窗开发流程:
1.`MessageKey.cs` 中定义枚举
2.`LanguageResourceHelper.ResourceKeyMap` 中增加映射
3.`MXJM_CN.xaml` 中补中文资源
4.`MXJM_EN.xaml` 中补英文资源
5. 业务代码统一调用 `LocalizedMessageBox.Show()``ShowFormat()`
## Required Title Keys
Use:
- MessageKey.TitleInfo
- MessageKey.TitleWarning
- MessageKey.TitleError
- MessageKey.TitleConfirm
## 中文说明
弹窗标题统一使用:
- `MessageKey.TitleInfo`
- `MessageKey.TitleWarning`
- `MessageKey.TitleError`
- `MessageKey.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:
1. Define MessageKey enum values for all error/status messages
2. Register in LanguageResourceHelper.ResourceKeyMap
3. Add translations in MXJM_CN.xaml and MXJM_EN.xaml
4. Pass MessageKey enum (not raw strings) in WorkflowContext or result objects
5. 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 实现
必须遵循与弹窗相同的本地化规范:
1. 在 MessageKey 中定义所有错误/状态消息的枚举值
2. 在 LanguageResourceHelper.ResourceKeyMap 中注册
3. 在 MXJM_CN.xaml 和 MXJM_EN.xaml 中添加对应翻译
4. 在 WorkflowContext 或结果对象中传递 MessageKey 枚举值(不是原始字符串)
5. 从 ViewModel/View 层使用 LocalizedMessageBox 显示消息
不允许在 Service/Activity 代码中硬编码错误信息或状态字符串。
## Example: Adding Workflow Error Message
For a new workflow error in a Service:
1. Define in `MessageKey.cs`:
```csharp
ProcessError_InvalidToolId,
ProcessError_HardwareTimeout,
```
2. Add to `LanguageResourceHelper.ResourceKeyMap`:
```csharp
{ MessageKey.ProcessError_InvalidToolId,
"MXJM:ProcessError_InvalidToolId" },
{ MessageKey.ProcessError_HardwareTimeout,
"MXJM:ProcessError_HardwareTimeout" },
```
3. In result object, return the message key:
```csharp
public MessageKey? ErrorMessageKey { get; set; }
```
4. In Activity's AfterExecute or ViewModel, check and display:
```csharp
if (result.ErrorMessageKey.HasValue)
{
LocalizedMessageBox.Show(result.ErrorMessageKey.Value,
MessageKey.TitleError);
}
```
## 中文说明
以工作流错误为例:
1. 在 `MessageKey.cs` 中定义:
ProcessError_InvalidToolId
ProcessError_HardwareTimeout
2. 在 `LanguageResourceHelper.ResourceKeyMap` 中注册
3. 在 Service 返回对象中包含 MessageKey
4. 在 Activity AfterExecute 或 ViewModel 中检查并使用 LocalizedMessageBox 显示