Skip to content

feat: add review-rendered-diff skill - #1252

Merged
josix merged 3 commits into
python:3.15from
josix:claude/review-rendered-diff-skill
Oct 27, 2026
Merged

josix merged 3 commits into
python:3.15from
josix:claude/review-rendered-diff-skill

Conversation

@josix

@josix josix commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

背景

Review 翻譯 PR 時,通常只看得到 .po 的 diff。但 reST 標記、斷行、全半形標點的效果,要 render 成網頁後才看得出來,例如括號在頁面上的實際寬度、強調語法是否生效。目前只能手動 make build、自己開頁面比對,很難把結果分享到 PR 上。

這個 PR 做了什麼

新增 review-rendered-diff skill(.claude/skills/review-rendered-diff/)。它會把 po 檔的翻譯修改 render 成實際的 Python 文件頁面,直接在頁面上標示差異,並為每個修改的段落截圖。

uv run .claude/skills/review-rendered-diff/scripts/render_diff.py howto/logging.po --base origin/3.15

相依套件以 PEP 723 inline metadata 宣告在 script 開頭,uv run 會自動安裝。

依修改的類型,自動選擇呈現方式:

修改類型 呈現方式
小幅修改既有譯文 在段落裡逐字標示:刪除的字是紅底加刪除線,新增的字是綠底
整段新翻譯(英文 → 中文) 上下兩個區塊:「原文 (English)」/「譯文」
大幅改寫既有譯文(改動超過 50%) 上下兩個區塊:「修改前」/「修改後」

其他特點:

  • 不動工作目錄: 兩個版本的 po 各自放進暫存的 locale_dirs,只 build 那一頁。不會覆蓋工作目錄裡的 po,也不會像 make build 那樣把 po 硬連結進 ../cpython。
  • 自動定位: 用 polib 比對兩版的 msgstr,自動找出修改了哪些條目,以及每個條目在頁面上對應的段落。
  • 多檔與單一 commit: 可以一次處理多個 po,也可以審查某個過去的 commit(--base <sha>^ --new <sha>)。
  • 速度: 每個 po 約 40 秒。

其他修改:

  • README.rst:在「使用 Skills 協助翻譯」章節加入這個 skill,並補上第三步的使用範例。
  • .gitignore:忽略 skill 的預設輸出目錄 .render-review/。

Codex 透過 .codex/skills 符號連結載入 skill,所以也會自動載入這個 skill。

驗證

  • 用三組真實的變動測試:
    • feat: translate howto/logging.po #1195(howto/logging.po 新翻譯):143 段用「原文/譯文」區塊,3 段短標題用行內標示,1 段整段改寫用「修改前/修改後」,沒有段落被跳過。表格內的條目放在儲存格裡,表格結構不受影響。
    • fix: refine howto/logging.po wording #1251(howto/logging.po 的小幅修正):7 段都用行內紅綠標示。
    • d99bb69(6 個 tutorial po 的修正):所有修改段落都正確定位。
  • 另外請一個只讀 SKILL.md 的 agent 實際跑一次 d99bb69。它發現了 msgstr 以 :: 結尾時找不到段落的 bug,也指出 SKILL.md 有幾處不清楚,都已修正。
  • ruff check:通過。
  • README:用 docutils 解析過,新加的段落沒有警告。
  • 每次執行前後,工作目錄的 po 都和原本相同。

🤖 Generated with Claude Code

https://claude.ai/code/session_014pJTfUKUkCc4HFprcvhxRe

…on rendered pages

Builds a page before and after a PO change in isolation (temp locale_dirs,
no changes to the working tree or ../cpython), then highlights each changed
paragraph on the real rendered HTML and screenshots it:
- small edits as inline red/green diffs
- new translations and heavy rewrites as stacked before/after blocks

Also lists the skill in README and ignores its default output dir.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014pJTfUKUkCc4HFprcvhxRe
@josix
josix marked this pull request as ready for review October 26, 2026 15:22
- Treat fuzzy msgstr as untranslated, since Sphinx does not render it
- Pick the closest, not-yet-highlighted block when the snippet appears
  in several paragraphs (asdict/astuple, class C/D __init__ examples)
- Ignore URLs when measuring CJK share, so short Chinese text around a
  long URL is not labelled as English
- Show whitespace-only changes as ␣ instead of an empty colored box
- Resolve --out to an absolute path
- Fix ruff warnings (explicit check=False, narrow Playwright exception)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014pJTfUKUkCc4HFprcvhxRe
mattwang44
mattwang44 previously approved these changes Oct 27, 2026
Comment thread .claude/skills/review-rendered-diff/scripts/render_diff.py Outdated
`uv run <script>` now installs polib, beautifulsoup4, playwright and
pillow itself, so the --no-project/--with flags are no longer needed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014pJTfUKUkCc4HFprcvhxRe
@josix
josix merged commit db7d718 into python:3.15 Oct 27, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants