|
| 1 | +# Automatic Document Translation |
1 | 2 |
|
| 3 | +Multi-language document auto-translation system based on GitHub Actions and Dify AI, supporting English, Chinese, and Japanese trilingual translation. |
| 4 | + |
| 5 | +> **Other Languages**: [中文](README.md) | [日本語](README_JA.md) |
| 6 | +
|
| 7 | +## How It Works |
| 8 | + |
| 9 | +1. **Trigger Condition**: Automatically runs when pushing to non-main branches |
| 10 | +2. **Smart Detection**: Automatically identifies modified `.md/.mdx` files and determines source language |
| 11 | +3. **Translation Logic**: |
| 12 | + - ✅ Translates new documents to other languages |
| 13 | + - ❌ Skips existing translation files (avoids overwriting manual edits) |
| 14 | +4. **Auto Commit**: Translation results are automatically pushed to the current branch |
| 15 | + |
| 16 | +## System Features |
| 17 | + |
| 18 | +- 🌐 **Multi-language Support**: Configuration-based language mapping, theoretically supports any language extension |
| 19 | +- 📚 **Terminology Consistency**: Built-in professional terminology database, LLM intelligently follows terminology to ensure unified technical vocabulary translation |
| 20 | +- 🔄 **Concurrent Processing**: Smart concurrency control, translates multiple target languages simultaneously |
| 21 | +- 🛡️ **Fault Tolerance**: 3-retry mechanism with exponential backoff strategy |
| 22 | +- ⚡ **Incremental Translation**: Only processes changed files, avoids redundant work |
| 23 | +- 🧠 **High-Performance Models**: Uses high-performance LLM models to ensure translation quality |
| 24 | + |
| 25 | +## Usage |
| 26 | + |
| 27 | +### For Document Writers |
| 28 | + |
| 29 | +1. Write/modify documents in any language directory |
| 30 | +2. Push to branch (non-main) |
| 31 | +3. Wait 0.5-1 minute for automatic translation completion |
| 32 | +4. **View Translation Results**: |
| 33 | + - Create Pull Request for local viewing and subsequent editing |
| 34 | + - Or view Actions push commit details on GitHub to directly review translation quality |
| 35 | + |
| 36 | +### Supported Language Directories |
| 37 | + |
| 38 | +- **General Documentation**: `en/` ↔ `zh-hans/` ↔ `ja-jp/` |
| 39 | +- **Plugin Development Documentation**: `plugin-dev-en/` ↔ `plugin-dev-zh/` ↔ `plugin-dev-ja/` |
| 40 | + |
| 41 | +Note: System architecture supports extending more languages, just modify configuration files |
| 42 | + |
| 43 | +## Important Notes |
| 44 | + |
| 45 | +- System only translates new documents, won't overwrite existing translations |
| 46 | +- To update existing translations, manually delete target files then retrigger |
| 47 | +- Terminology translation follows professional vocabulary in `termbase_i18n.md`, LLM has intelligent terminology recognition capabilities |
| 48 | +- Translation quality depends on configured high-performance models, recommend using high-performance base models in Dify Studio |
| 49 | + |
| 50 | +### System Configuration |
| 51 | + |
| 52 | +#### Terminology Database |
| 53 | + |
| 54 | +Edit `tools/translate/termbase_i18n.md` to update professional terminology translation reference table. |
| 55 | + |
| 56 | +#### Translation Model |
| 57 | + |
| 58 | +Visit Dify Studio to adjust translation prompts or change base models. |
| 59 | + |
| 60 | +--- |
| 61 | + |
| 62 | +## 🔧 Development and Deployment Configuration |
| 63 | + |
| 64 | +### Local Development Environment |
| 65 | + |
| 66 | +#### 1. Create Virtual Environment |
| 67 | + |
| 68 | +```bash |
| 69 | +# Create virtual environment |
| 70 | +python -m venv venv |
| 71 | + |
| 72 | +# Activate virtual environment |
| 73 | +# macOS/Linux: |
| 74 | +source venv/bin/activate |
| 75 | +# Windows: |
| 76 | +# venv\Scripts\activate |
| 77 | +``` |
| 78 | + |
| 79 | +#### 2. Install Dependencies |
| 80 | + |
| 81 | +```bash |
| 82 | +pip install -r tools/translate/requirements.txt |
| 83 | +``` |
| 84 | + |
| 85 | +#### 3. Configure API Key |
| 86 | + |
| 87 | +Create `.env` file in `tools/translate/` directory: |
| 88 | + |
| 89 | +```bash |
| 90 | +DIFY_API_KEY=your_dify_api_key_here |
| 91 | +``` |
| 92 | + |
| 93 | +#### 4. Run Translation |
| 94 | + |
| 95 | +```bash |
| 96 | +# Interactive mode (recommended for beginners) |
| 97 | +python tools/translate/main.py |
| 98 | + |
| 99 | +# Command line mode (specify file) |
| 100 | +python tools/translate/main.py path/to/file.mdx [DIFY_API_KEY] |
| 101 | +``` |
| 102 | + |
| 103 | +> **Tip**: Right-click in IDE and select "Copy Relative Path" to use as parameter |
| 104 | +
|
| 105 | +### Deploy to Other Repositories |
| 106 | + |
| 107 | +1. **Copy Files**: |
| 108 | + - `.github/workflows/translate.yml` |
| 109 | + - `tools/translate/` entire directory |
| 110 | + |
| 111 | +2. **Configure GitHub Secrets**: |
| 112 | + - Repository Settings → Secrets and variables → Actions |
| 113 | + - Add `DIFY_API_KEY` secret |
| 114 | + |
| 115 | +3. **Test**: Modify documents in branch to verify automatic translation functionality |
| 116 | + |
| 117 | +### Technical Details |
| 118 | + |
| 119 | +- Concurrent translation limited to 2 tasks to avoid excessive API pressure |
| 120 | +- Supports `.md` and `.mdx` file formats |
| 121 | +- Based on Dify API workflow mode |
| 122 | + |
| 123 | +## TODO |
| 124 | + |
| 125 | +- [ ] Support updating existing translations |
0 commit comments