Files
syops/docs/skills/add-i18n-keys-skill.md
T
hugoandCursor 39fe3c05f2 feat(freight-rpa): 库存/收料改名在手/入站,报表归属RPA,类名统一FreightRpa
把 shipping 侧 inventory/receipt 词根迁到 onhand/inbound,29 张表与
枚举/权限/前端/i18n 同步改名;在手与入站报表配置及文件改由 freight_rpa
持有,发货与调拨仅按 source_code 消费;ORM 类加 FreightRpa 前缀,
上传动作改为 freight_rpa_upload。含类名与上传动作改名规格文档。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-19 10:46:06 +08:00

178 lines
6.5 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.
# add-i18n-keys Skill 使用说明
> 文档定位:说明 HXOPS 项目级 Cursor Skill **`add-i18n-keys`** 的用途、触发方式与落地约定。
> Agent 执行细则以 [`.cursor/skills/add-i18n-keys/SKILL.md`](../../.cursor/skills/add-i18n-keys/SKILL.md) 为准;错误码契约以 [error_handling.md](../convention/error_handling.md) 为准。
---
## 1. 背景与目标
HXOPS 前端使用 Vue I18n,用户可见文案必须同时覆盖四种语言:
| Locale | 目录 |
| --- | --- |
| 简体中文 | `frontend/src/locales/zh-CN/` |
| 繁体中文 | `frontend/src/locales/zh-TW/` |
| English | `frontend/src/locales/en/` |
| ไทย | `frontend/src/locales/th/` |
`AGENTS.md` §8 已将「四语言、禁止硬编码中文」列为红线。本 Skill 把该红线落成**可重复的工作流**:选域 → 四文件同步 → 代码引用 →(如需)注册新域 / 补错误码。
---
## 2. 文件位置
```text
.cursor/skills/add-i18n-keys/
├── SKILL.md # Agent 执行说明书(自动/显式触发时加载)
└── domains.md # 域选择与 auth/kb 展平补充说明
```
| 类型 | 路径 | 说明 |
| --- | --- | --- |
| 项目 Skill | `.cursor/skills/add-i18n-keys/` | 随仓库共享,拉代码即可用 |
| 文案数据 | `frontend/src/locales/{locale}/*.json` | 按业务域拆分 |
| 合并入口 | `frontend/src/locales/index.ts` | 新域 JSON 必须在此注册 |
与常驻规则的关系:
| | `AGENTS.md` / `.cursor/rules` | `add-i18n-keys` skill |
| --- | --- | --- |
| **作用** | 常驻原则(必须四语言) | 可执行工作流(怎么改、改哪、checklist) |
| **何时生效** | 几乎每次对话 | 提到 i18n / 改 locales / 加文案时 |
---
## 3. 何时使用
适合在以下场景启用本 Skill:
- 新增/修改按钮、标题、提示、对话框、占位符、Toast 等 UI 文案
- 把组件里的硬编码中文改为 i18n key
- 编辑 `frontend/src/locales/**`
- 后端新增 `error.code`,需同步前端 `errors.codes.*`
- 新建业务域 locale 文件(如 `shipping.json`)并完成注册
不适合:纯后端无用户文案的改动、仅改逻辑不改展示文案的任务(除非顺带涉及错误码)。
---
## 4. 怎么用(给开发者)
### 4.1 自然语言(推荐)
在 Cursor Agent 对话中直接描述需求即可。Skill 的 `description` 含触发词(i18n、国际化、四语言、locale、`errors.json` 等),相关请求会自动匹配:
```text
给 ChatInputBar 的「清除焦点」按钮补齐四语言,放到 chat.shippingNoticeUi 下
```
```text
把这个页面里硬编码的中文改成 i18n,别漏繁中/英/泰
```
```text
后端新增 SHIPPING.FOO_BAR,按四语言补 errors.codes
```
### 4.2 显式点名
需要强制走该流程时,在对话中写出 skill 名:
```text
用 add-i18n-keys:在 admin 域增加「批量导出」文案并接到按钮
```
或:
```text
/add-i18n-keys 为 profile 页保存成功提示补齐四语言
```
### 4.3 写功能时顺带使用
做前端功能时可补充一句「文案走 i18n / 四语言」,Agent 应按 Skill 同步改四个 JSON 与 `t()` / `$t()` 引用,而不是只改 `zh-CN`。
---
## 5. Agent 会执行的流程(摘要)
1. **选域与 key**:按功能选 `chat` / `common` / `admin` 等;共享文案用 `common`;key 用 camelCase,可按 UI 区块嵌套。
2. **四语言同路径写入**:同一 JSON 路径出现在 `zh-CN` / `zh-TW` / `en` / `th`;仅 value 不同;要求真实翻译(繁中勿直接复制简中)。
3. **代码引用**:模板用 `$t('…')`,脚本用 `useI18n()` 的 `t('…')`;禁止残留硬编码用户文案。
4. **新域文件**(如有):四个 locale 目录各加一份 JSON,并在 `locales/index.ts` 的 `externalModules` 注册;新域默认**带文件名命名空间**(不要仿照 auth/kb 做 spread 展平)。
5. **API 错误码**(如有):`USER.EMAIL_EXISTS` → `errors.codes.USER_EMAIL_EXISTS`(`.` 换 `_`),四语言同步;详见 [error_handling.md](../convention/error_handling.md)。
### Key 路径速查
| 域文件 | 运行时前缀 | 示例 |
| --- | --- | --- |
| 多数域(`chat.json`、`common.json`…) | `<文件名>.…` | `t('common.cancel')` |
| `auth.json` | **展平到根** | `t('login.submit')`(不是 `auth.login.submit`) |
| `kb.json` | **展平到根** | `t('kbDifySettings.title')` |
| `errors.json` | `errors.…` | `t('errors.codes.AUTH_UNAUTHORIZED')` |
域职责细表见 Skill 内 [domains.md](../../.cursor/skills/add-i18n-keys/domains.md)。
---
## 6. 示例
### 6.1 普通 UI 文案
**请求:**
```text
在 chat.shippingNoticeUi 下加 clearFocus,中文「清除焦点」,接到按钮
```
**期望结果:**
- 四个 `chat.json` 增加相同路径,例如 `shippingNoticeUi.clearFocus`
- 组件使用 `$t('chat.shippingNoticeUi.clearFocus')` 或 `t('…')`
### 6.2 带插值
```ts
t('common.pagination.summary', { total, page, pages })
```
JSON 中保留命名占位符,例如 `"共 {total} 条,当前第 {page} / {pages} 页"`。
### 6.3 新增错误码
**后端 code:** `SHIPPING.ONHAND_SOURCE_INVALID`
**前端 key:** `errors.codes.SHIPPING_ONHAND_SOURCE_INVALID`
**文件:** `frontend/src/locales/{zh-CN,zh-TW,en,th}/errors.json` 的 `codes` 对象下各加一条。
---
## 7. 完成自检
- [ ] 变更路径在四语言文件中 key 树一致
- [ ] UI 仅通过 i18n key 展示文案
- [ ] 新域已在 `frontend/src/locales/index.ts` 注册(若适用)
- [ ] 新 `error.code` 已写入四语言 `errors.codes.*`(若适用)
- [ ] 涉及 `frontend/` 时本地 `npm run build` 可通过(合并前最低自检)
---
## 8. 维护说明
- 修改 Skill 行为时:同步更新 `.cursor/skills/add-i18n-keys/SKILL.md`(及必要时 `domains.md`)与**本文**。
- 新增 locale 域文件或改变展平规则时:更新 `locales/index.ts`、Skill 与本文的域表。
- 错误码命名与映射规则变更时:以 [error_handling.md](../convention/error_handling.md) 为准,并回改 Skill 中对应步骤。
---
## 9. 相关链接
| 资源 | 路径 |
| --- | --- |
| Skill 正文 | [`.cursor/skills/add-i18n-keys/SKILL.md`](../../.cursor/skills/add-i18n-keys/SKILL.md) |
| 域补充 | [`.cursor/skills/add-i18n-keys/domains.md`](../../.cursor/skills/add-i18n-keys/domains.md) |
| Locale 合并 | [`frontend/src/locales/index.ts`](../../frontend/src/locales/index.ts) |
| 错误处理规范 | [error_handling.md](../convention/error_handling.md) |
| Skills 索引 | [README.md](README.md) |
| 协作总入口 | [AGENTS.md](../../AGENTS.md) |