sync-pd2-wiki/.claude/skills/wiki-sync-translate/SKILL.md

139 lines
10 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.

---
name: wiki-sync-translate
description: 同步英文 MediaWiki 页面变更到中文翻译文档。当用户需要更新中文 Wiki页面、同步英文变更、或翻译 Wiki 内容时触发。适用于 Project Diablo 2 Wiki 的中英双语同步维护场景。
---
# Wiki 同步翻译
同步英文 Wiki 页面变更到中文翻译文档,保持行号一致。
## 使用方法
- 用户请求更新中文 Wiki 页面
- 用户请求同步英文 Wiki 变更
- 用户指定某个页面需要进行翻译更新
- 用户执行 `/wiki-sync-translate <页面名称>`
## 工作目录
脚本位于:`.claude/skills/wiki-sync-translate/scripts/wiki_sync.py`
## 执行步骤
### Step 1: 运行同步脚本
使用 skill 目录下的专用脚本获取变更:
```bash
cd /mnt/d/code/sync-pd2-wiki
source venv/bin/activate
python .claude/skills/wiki-sync-translate/
scripts/wiki_sync.py --title "<页面名称>" --since <上次同步时间> --run
```
参数说明:
- `--title`: 指定要同步的页面名称
- `--since`: 起始时间,格式如 `2026-01-02T12:07:05Z`
- `--run`: 必须提供此参数才会执行
### Step 2: 读取输出文件
脚本会在 `wiki_sync_output/<时间戳>/changed_pages/` 目录下生成:
| 文件 | 说明 | 用途 |
|------|------|------|
| `*.comparison.json` | 结构化变更信息 | **AI 读取,包含行号和变更内容** |
| `*.full.txt` | 英文最新版本 | 参考对照 |
| `*.cn.txt` | 中文原文 | **基于此文件进行修改** |
| `*.old.txt` | 英文历史版本 | 参考对照 |
### Step 3: 解析 comparison.json
`comparison.json` 格式:
```json
{
"title": "页面标题",
"has_cn_translation": true,
"summary": {
"total_changes": 1,
"replaced": 1,
"added": 0,
"removed": 0
},
"changes": [
{
"type": "replaced",
"old_line": 66,
"new_line": 66,
"old_content": "旧内容",
"new_content": "新内容"
}
]
}
```
变更类型:
- `replaced`: 替换,`old_line` 表示需要修改的行号
- `added`: 新增,`new_line` 表示插入位置
- `removed`: 删除,`old_line` 表示要删除的行
### Step 4: 更新中文文档
**核心原则:行号必须完全一致**
1. 创建 `wiki_sync_output/<时间戳>/result_pages/` 目录(如不存在)
2. 复制 `*.cn.txt` 内容到 `result_pages/<页面名>.cn.txt`
3. 根据 `changes` 中的行号定位对应行
4. 智能更新:
- 仅同步变更的内容
- 保留中文翻译(如 "赛季 12" 不改为 "Season 12"
- 新增的英文内容智能翻译成中文,可以用`grep` 命令在`references/PatchString.txt` 搜索技能或物品的中文名称,搜索不到的则智能翻译按照暗黑破坏神2的常用命名。
- 保持 MediaWiki 语法正确,语法可以参照`mediawiki-wikitest` skill.
5. 保存到 `wiki_sync_output/<时间戳>/result_pages/<页面名>.cn.txt`
### Step 5: 输出结果
将更新后的文档保存到 `wiki_sync_output/<时间戳>/result_pages/<页面名>.cn.txt`,用户可直接复制到 Wiki。
## 示例
**输入 - comparison.json:**
```json
{
"changes": [{
"type": "replaced",
"old_line": 66,
"old_content": "| style=\"...\"| 2025-11-25<br>(Season 12)",
"new_content": "| style=\"...\"| 2026-01-25<br>(Season 12)"
}]
}
```
**中文原文第66行**
```
| style="color:#3f6e2d; background-color:#161f0c; border-color:#0d1709"| 2025-11-25<br>(赛季 12)
```
**更新后第66行**
```
| style="color:#3f6e2d; background-color:#161f0c; border-color:#0d1709"| 2026-01-25<br>(赛季 12)
```
**变更说明:** 日期 `2025-11-25``2026-01-25`,但 `赛季 12` 保持中文不变。
## 注意事项
1. **行号一致性**:确保中英文文档行号完全对应,这是长期维护的基础
2. **保留翻译**:只同步变更内容,不替换已有的中文翻译
3. **MediaWiki 语法**
- 表格分隔符 `|-` 位置保持一致
- 链接格式 `[[页面名|显示文本]]` 不变
- 样式属性 `style="..."` 不变
4. **特殊字符**:注意 `<br>`、`&nbsp;` 等 HTML 实体
## 错误处理
- 如果 `has_cn_translation` 为 false提示用户该页面无中文翻译
- 如果 `is_new_page` 为 true说明是新页面需要全新翻译
- 如果找不到对应行,可能是中英文版本不同步,需要人工确认