From 6f9e567a1eccecdf42b05cab497a70b67347df0a Mon Sep 17 00:00:00 2001 From: Kai Tomotake Date: Tue, 26 May 2026 17:51:40 +0900 Subject: [PATCH 1/2] Add automatic translation Actions file. --- .github/workflows/translation.yml | 104 ++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 .github/workflows/translation.yml diff --git a/.github/workflows/translation.yml b/.github/workflows/translation.yml new file mode 100644 index 0000000..12c5d85 --- /dev/null +++ b/.github/workflows/translation.yml @@ -0,0 +1,104 @@ +name: Auto Translate + +concurrency: + group: auto-translate + cancel-in-progress: false + +on: + schedule: + - cron: '0 */12 * * *' + workflow_dispatch: + +jobs: + translate: + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + + steps: + - name: Checkout source branch + uses: actions/checkout@v6 + with: + ref: source + fetch-depth: 0 + + - name: Fetch source branch + run: git fetch origin main + + - name: Pick a random file + id: pick + run: | + target="$(find . -path './pr_created' -prune -o -type f -name '*.mdx' -print | shuf -n 1)" + if [ -z "$target" ]; then + echo "No MDX files found" + exit 1 + fi + echo "target=$target" >> $GITHUB_OUTPUT + + - name: Read source MDX + id: read + run: | + delim=$(uuidgen) + { + echo "body<<$delim" + cat ${{ steps.pick.outputs.target }} + echo $delim + } >> $GITHUB_OUTPUT + + - name: Translate with Claude + id: translate + uses: anthropics/claude-code-action@v1 + with: + anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} + prompt: | + 以下のmdxについて、コードブロック・タグ・フロントマターのキー以外を日本語に翻訳してください。 + + ${{ steps.read.outputs.body }} + claude_args: | + --model claude-sonnet-4-6 \ + --output-format json \ + --json-schema '{ + "type": "object", + "properties": { + "translated": {"type": "string"} + }, + "required": ["translated"] + }' + + - name: Commit translated file + id: commit + env: + TRANSLATED: ${{ steps.translate.outputs.structured_output }} + run: | + path="contents/docs/${{ steps.pick.outputs.target }}" + branch="translate-$(uuidgen | cut -c1-8)" + git config user.name "github-actions" + git config user.email "github-actions@users.noreply.github.com" + git checkout -b $branch origin/main + mkdir -p "$(dirname $path)" + echo "$TRANSLATED" | jq -r ".translated" > $path + git add $path + git commit -m "Translate ${{ steps.pick.outputs.target }}" + git push -u origin $branch + echo "branch=$branch" >> $GITHUB_OUTPUT + + - name: Create PR + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh pr create \ + --base main \ + --head ${{ steps.commit.outputs.branch }} \ + --title "Translate ${{ steps.pick.outputs.target }}" \ + --body "Auto-generated translation PR" + + - name: Move the file + run: | + git checkout source + dest="pr_created/${{ steps.pick.outputs.target }}" + mkdir -p "$(dirname "$dest")" + mv "${{ steps.pick.outputs.target }}" "$dest" + git add "$dest" "${{ steps.pick.outputs.target }}" + git commit -m "Move PR-created file to pr_created" + git push -u origin source From 3e78f64815cee5d01b89fe50a4645f3582961217 Mon Sep 17 00:00:00 2001 From: Kai Tomotake Date: Tue, 26 May 2026 18:03:01 +0900 Subject: [PATCH 2/2] fix --- .github/workflows/translation.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/translation.yml b/.github/workflows/translation.yml index 12c5d85..aa6964d 100644 --- a/.github/workflows/translation.yml +++ b/.github/workflows/translation.yml @@ -6,7 +6,7 @@ concurrency: on: schedule: - - cron: '0 */12 * * *' + - cron: "0 */12 * * *" workflow_dispatch: jobs: @@ -15,7 +15,7 @@ jobs: permissions: contents: write pull-requests: write - + steps: - name: Checkout source branch uses: actions/checkout@v6 @@ -25,7 +25,7 @@ jobs: - name: Fetch source branch run: git fetch origin main - + - name: Pick a random file id: pick run: | @@ -45,7 +45,7 @@ jobs: cat ${{ steps.pick.outputs.target }} echo $delim } >> $GITHUB_OUTPUT - + - name: Translate with Claude id: translate uses: anthropics/claude-code-action@v1 @@ -53,7 +53,7 @@ jobs: anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} prompt: | 以下のmdxについて、コードブロック・タグ・フロントマターのキー以外を日本語に翻訳してください。 - + ${{ steps.read.outputs.body }} claude_args: | --model claude-sonnet-4-6 \ @@ -84,7 +84,7 @@ jobs: echo "branch=$branch" >> $GITHUB_OUTPUT - name: Create PR - env: + env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | gh pr create \