Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/auto-translate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Auto Translate

on:
push:
branches: [dev]
paths:
- 'packages/web/src/content/docs/docs/*.mdx'
- 'packages/web/src/content/docs/docs/*.md'

jobs:
translate:
runs-on: ubuntu-latest
permissions:
contents: write # Need write permission for creating branches, commits, etc.
id-token: write # Generate JWT token for GitHub API calls
pull-requests: write # Need write permission for creating pull requests

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: dev
fetch-depth: 0 # Need full history to detect changes

- name: Run translation
uses: ./auto-translate
with:
model: anthropic/claude-sonnet-4-20250514
source_lang: 'en'
target_lang: 'zh'
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
97 changes: 97 additions & 0 deletions auto-translate/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Dependencies
node_modules/
npm-debug.log*
yarn-debug.log*
yarn-error.log*
bun.lock

# Environment variables
.env
.env.local
.env.*.local

# Logs
*.log
logs/

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Coverage directory used by tools like istanbul
coverage/
*.lcov

# nyc test coverage
.nyc_output

# Dependency directories
jspm_packages/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# next.js build output
.next

# nuxt.js build output
.nuxt

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# OS generated files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

# IDE files
.vscode/
.idea/
*.swp
*.swo
*~

# Temporary files
*.tmp
*.temp
139 changes: 139 additions & 0 deletions auto-translate/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# Auto Translate Action

Automatically translate English documentation to Chinese using GitHub Actions.

## Features

- 🚀 **Auto-trigger**: Automatically triggers translation when English docs are updated
- 🤖 **AI-powered**: Uses Claude AI for high-quality translation
- 📝 **Smart detection**: Automatically detects document changes (added, modified, deleted)
- 🔄 **Branch management**: Creates independent translation branches without affecting main branch
- 📋 **PR creation**: Automatically creates translation PRs for human review
- 🌏 **Multi-language support**: Supports multiple language pairs (currently English → Chinese)

## Usage

### 1. Reference in workflow

```yaml
name: Auto Translate

on:
push:
branches: [dev]
paths:
- 'packages/web/src/content/docs/docs/**/*.mdx'
- 'packages/web/src/content/docs/docs/**/*.md'

jobs:
translate:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
id-token: write

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: dev
fetch-depth: 0

- name: Run translation
uses: ./auto-translate
with:
model: anthropic/claude-sonnet-4-20250514
source_lang: 'en'
target_lang: 'zh'
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
```

### 2. Configure environment variables

Add to repository Secrets:
- `ANTHROPIC_API_KEY`: Anthropic API key

### 3. Configure permissions

Ensure workflow has sufficient permissions:
- `contents: write`: Update Chinese documentation
- `pull-requests: write`: Create translation PRs
- `id-token: write`: Generate JWT token

## Workflow

1. **Trigger detection**: Monitors English doc changes pushed to dev branch
2. **Change analysis**: Analyzes added, modified, and deleted documents
3. **AI translation**: Calls Claude AI for document translation
4. **Branch creation**: Creates independent translation branch
5. **File updates**: Updates corresponding Chinese documentation
6. **Commit & push**: Commits translation results and pushes to remote
7. **PR creation**: Automatically creates translation PR for review

## Input Parameters

| Parameter | Description | Required | Default |
|-----------|-------------|----------|---------|
| `model` | AI model | Yes | `anthropic/claude-sonnet-4-20250514` |
| `source_lang` | Source language | Yes | `en` |
| `target_lang` | Target language | Yes | `zh` |
| `token` | GitHub token | No | `GITHUB_TOKEN` |

## Output

- Automatically creates translation branch
- Updates Chinese documentation files
- Creates translation PR
- Detailed execution logs

## Technical Architecture

```
Workflow → Action → Business Logic
├── Trigger condition check
├── Environment configuration
├── Dependency installation
├── Document change detection
├── AI translation call
├── Git operations
└── PR creation
```

## Requirements

- Node.js 18+
- Bun 1.0+
- GitHub Actions v4

## Notes

- Translation quality requires human review
- Ensure API key security configuration
- Recommend testing in test environment before deploying to production

## Troubleshooting

### Common Issues

1. **Insufficient permissions**: Check workflow permission configuration
2. **API call failure**: Verify API key is correct
3. **Git operation failure**: Confirm repository access permissions
4. **Poor translation quality**: Adjust translation prompts or use better models

### Log Viewing

View detailed execution logs in GitHub Actions page, including:
- Document change detection results
- AI translation call status
- Git operation execution
- Error messages and stack traces

## Contributing

Welcome to submit Issues and Pull Requests to improve this Action!

## License

MIT License
47 changes: 47 additions & 0 deletions auto-translate/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: "Auto Translate Action"
description: "Automatically translate English documentation to Chinese using AI"
branding:
icon: "globe"
color: "blue"

inputs:
model:
description: "The AI model to use for translation. Takes the format of `provider/model`."
required: true
default: "anthropic/claude-sonnet-4-20250514"

source_lang:
description: "Source language for translation."
required: true
default: "en"

target_lang:
description: "Target language for translation."
required: true
default: "zh"

runs:
using: "composite"
steps:
- name: Install opencode
shell: bash
run: curl -fsSL https://opencode.ai/install | bash

- name: Install bun
shell: bash
run: npm install -g bun

- name: Install dependencies
shell: bash
run: |
cd ${GITHUB_ACTION_PATH}
bun install

- name: Run translation
shell: bash
run: bun ${GITHUB_ACTION_PATH}/index.ts
env:
MODEL: ${{ inputs.model }}
SOURCE_LANG: ${{ inputs.source_lang }}
TARGET_LANG: ${{ inputs.target_lang }}
TOKEN: ${{ github.token }}
Loading