ClaudeとGitHub Actionsによるブログの自動翻訳
私が書くすべての記事は自動的に翻訳されます。Claudeが翻訳を処理し、結果をmainにコミットし、翻訳版はオリジナルと一緒にデプロイされます。
フロー
翻訳ワークフローは、英語コンテンツがmainにマージされるとGitHub Actionsで実行されます:
on:
push:
branches: [main]
paths:
- 'content/**/*.en.md'
flowchart LR
B[mainにマージ] --> C[翻訳が生成される]
C --> D[mainにコミット]
D --> E[全言語で本番デプロイ]
プロンプト
ワークフローはclaude-code-actionを使用します:
For each .en.md file that was added or modified:
1. Read the English content
2. Create translations for these languages: es, nl, de, it, fr, ja, zh, ru, hi
3. Save each translation as filename.{lang}.md (e.g., hello-world.es.md)
4. Preserve the frontmatter structure exactly, but translate the title
5. Translate the body content naturally
6. Keep code blocks, URLs, file paths, and technical terms unchanged
1つのプロンプトで9言語すべてを処理します。「自然に翻訳する」は「このテキストを翻訳する」よりも流暢な出力を生成します。コードブロックと技術用語は英語のままです。
フロントマターの処理
Hugoの記事にはYAMLフロントマターがあります。翻訳すべきフィールド(タイトル)と、そうでないもの(日付、スラッグ)があります:
「フロントマターの構造を正確に保持し、タイトルのみ翻訳する」
英語:
---
title: "Hello World"
date: 2025-12-20
draft: false
---
ヒンディー語:
---
title: "नमस्ते दुनिया"
date: 2025-12-20
draft: false
---
コミット
ワークフローはボットIDを設定し、Claudeができることを制限します:
- name: Setup git identity
run: |
git config --global user.email "claude[bot]@users.noreply.github.com"
git config --global user.name "claude[bot]"
- name: Translate with Claude
uses: anthropics/claude-code-action@v1
with:
claude_args: "--allowedTools 'Write,Bash(git:*)'"
prompt: |
...
Use `git add`, `git commit`, and `git push` to add the translations directly to main.
--allowedToolsはClaudeをファイルの書き込みとgitコマンドの実行に制限します。
品質
個人ブログには十分です。Claudeの翻訳は流暢で意味をよく捉えています。ネイティブスピーカーは時折ぎこちない表現に気づくでしょうが、私自身ができるよりは良いです。
その他の用途
同じパターンはドキュメント生成、変更履歴の要約、コミットメッセージの作成、リリースノートにも使えます:
- 何が変更されたかを検出
- 指示とともにコンテンツをClaudeに送信
- 結果をブランチにコミット