172 lines
11 KiB
Markdown
172 lines
11 KiB
Markdown
---
|
||
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` | 结构化变更信息 | **必须读取,包含行号和变更内容** |
|
||
| `*.full.txt` | 英文最新版本 | 需要时参考 |
|
||
| `*.cn.txt` | 中文原文 | **复制到 result_pages,不直接读取** |
|
||
| `*.old.txt` | 英文历史版本 | 需要时参考 |
|
||
|
||
**重要:** 只读取 `comparison.json`,不要读取整个 `*.cn.txt` 文件以节省 token。
|
||
|
||
|
||
### 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` 表示要删除的行
|
||
|
||
**配对算法说明:**
|
||
从 v2 版本开始,脚本使用**内容相似度**来判断 `removed` 和 `added` 是否应该配对为 `replaced`:
|
||
- 相似度阈值设为 0.5(50%)
|
||
- 只有当 removed 和 added 的内容相似度 ≥ 0.5 时,才会被配对
|
||
- 这避免了将完全不同内容的行错误配对
|
||
|
||
**注意:** 如果 `old_line` 和 `new_line` 差距很大但内容相似(如行号从171变到193),这通常意味着中间有其他行被插入或删除,需要仔细检查变更是否真的相关。
|
||
|
||
### Step 4: 更新中文文档
|
||
|
||
**核心原则:行号必须完全一致,使用增量修改减少 token 消耗**
|
||
|
||
1. 创建 `wiki_sync_output/<时间戳>/result_pages/` 目录(如不存在)
|
||
2. **判断页面类型**:
|
||
- **已有中文翻译**(`has_cn_translation: true`):复制 `*.cn.txt` 到 result_pages,然后用 Edit 增量修改
|
||
- **新页面**(`has_cn_translation: false` 或 `is_new_page: true`):读取 `*.full.txt` 英文版本,翻译后直接 Write 到 result_pages
|
||
3. **使用 Edit 工具**增量修改(仅适用于已有翻译的页面):
|
||
- 根据 `old_line` 定位要修改的行
|
||
- 从 `*.cn.txt` 中提取该行的**完整内容**作为 `old_string`
|
||
- 构造新的行内容作为 `new_string`
|
||
- 智能更新规则:
|
||
- 仅同步变更的内容(如日期、数值)
|
||
- 保留中文翻译(如 "赛季 12" 不改为 "Season 12")
|
||
- 新增的英文内容智能翻译成中文,可以用 `Grep` 工具在 `references/PatchString.txt` 搜索技能或物品的中文名称
|
||
- 保持 MediaWiki 语法正确
|
||
4. 每次变更使用一次 Edit 调用
|
||
|
||
**示例操作流程:**
|
||
```bash
|
||
# 1. 复制文件
|
||
cp wiki_sync_output/<时间戳>/changed_pages/*.cn.txt wiki_sync_output/<时间戳>/result_pages/<页面名>.cn.txt
|
||
```
|
||
```json
|
||
// 2. 从 comparison.json 获取变更,假设第66行需要修改
|
||
// 3. 只读取该行附近内容确认,然后用 Edit 修改
|
||
```
|
||
|
||
### 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>`、` ` 等 HTML 实体
|
||
|
||
## 错误处理
|
||
|
||
- 如果 `has_cn_translation` 为 false,提示用户该页面无中文翻译
|
||
- 如果 `is_new_page` 为 true,说明是新页面,需要全新翻译
|
||
- 如果找不到对应行,可能是中英文版本不同步,需要人工确认
|
||
|
||
## 翻译术语表
|
||
|
||
翻译时参考 `references/PD2_glossary.md` 中的标准术语对照表,确保技能名称、灵气名称和通用术语的翻译一致。优先级高于模型自身的翻译选择。
|
||
|
||
## 翻译术语表
|
||
|
||
翻译时参考 `references/PD2_glossary.md` 中的标准术语对照表,确保所有技能名称、灵气名称和通用术语的翻译一致。 |