|
| 1 | +# Translation Tools for JavaGuide |
| 2 | + |
| 3 | +This repository includes automated translation tools to translate all documentation to multiple languages. |
| 4 | + |
| 5 | +## Available Tools |
| 6 | + |
| 7 | +### 1. Python Version (`translate_repo.py`) |
| 8 | + |
| 9 | +**Requirements:** |
| 10 | +```bash |
| 11 | +pip install deep-translator |
| 12 | +``` |
| 13 | + |
| 14 | +**Usage:** |
| 15 | +```bash |
| 16 | +python3 translate_repo.py |
| 17 | +``` |
| 18 | + |
| 19 | +**Features:** |
| 20 | +- ✅ Uses Google Translate (free, no API key required) |
| 21 | +- ✅ Translates all `.md` files in `docs/` folder + `README.md` |
| 22 | +- ✅ Preserves directory structure |
| 23 | +- ✅ Progress tracking (saves to `.translation_progress.json`) |
| 24 | +- ✅ Skips already translated files |
| 25 | +- ✅ Rate limiting to avoid API throttling |
| 26 | +- ✅ Supports 20 languages |
| 27 | + |
| 28 | +### 2. Java Version (`TranslateRepo.java`) |
| 29 | + |
| 30 | +**Requirements:** |
| 31 | +```bash |
| 32 | +# Requires Gson library |
| 33 | +# Download from: https://repo1.maven.org/maven2/com/google/code/gson/gson/2.10.1/gson-2.10.1.jar |
| 34 | +``` |
| 35 | + |
| 36 | +**Compile:** |
| 37 | +```bash |
| 38 | +javac -cp gson-2.10.1.jar TranslateRepo.java |
| 39 | +``` |
| 40 | + |
| 41 | +**Usage:** |
| 42 | +```bash |
| 43 | +java -cp .:gson-2.10.1.jar TranslateRepo |
| 44 | +``` |
| 45 | + |
| 46 | +**Features:** |
| 47 | +- ✅ Pure Java implementation |
| 48 | +- ✅ Uses Google Translate API (free, no key required) |
| 49 | +- ✅ Same functionality as Python version |
| 50 | +- ✅ Progress tracking with JSON |
| 51 | +- ✅ Supports 20 languages |
| 52 | + |
| 53 | +## Supported Languages |
| 54 | + |
| 55 | +1. English (en) |
| 56 | +2. Chinese Simplified (zh) |
| 57 | +3. Spanish (es) |
| 58 | +4. French (fr) |
| 59 | +5. Portuguese (pt) |
| 60 | +6. German (de) |
| 61 | +7. Japanese (ja) |
| 62 | +8. Korean (ko) |
| 63 | +9. Russian (ru) |
| 64 | +10. Italian (it) |
| 65 | +11. Arabic (ar) |
| 66 | +12. Hindi (hi) |
| 67 | +13. Turkish (tr) |
| 68 | +14. Vietnamese (vi) |
| 69 | +15. Polish (pl) |
| 70 | +16. Dutch (nl) |
| 71 | +17. Indonesian (id) |
| 72 | +18. Thai (th) |
| 73 | +19. Swedish (sv) |
| 74 | +20. Greek (el) |
| 75 | + |
| 76 | +## Output Structure |
| 77 | + |
| 78 | +Original: |
| 79 | +``` |
| 80 | +docs/ |
| 81 | +├── java/ |
| 82 | +│ └── basics.md |
| 83 | +└── ... |
| 84 | +README.md |
| 85 | +``` |
| 86 | + |
| 87 | +After translation to English: |
| 88 | +``` |
| 89 | +docs_en/ |
| 90 | +├── java/ |
| 91 | +│ └── basics.en.md |
| 92 | +└── ... |
| 93 | +README.en.md |
| 94 | +``` |
| 95 | + |
| 96 | +## How It Works |
| 97 | + |
| 98 | +1. **Scans** all `.md` files in `docs/` folder and `README.md` |
| 99 | +2. **Splits** large files into chunks (4000 chars) to respect API limits |
| 100 | +3. **Translates** each chunk using Google Translate |
| 101 | +4. **Preserves** markdown formatting and code blocks |
| 102 | +5. **Saves** to `docs_{lang}/` with `.{lang}.md` suffix |
| 103 | +6. **Tracks** progress to resume if interrupted |
| 104 | + |
| 105 | +## Example Workflow |
| 106 | + |
| 107 | +```bash |
| 108 | +# 1. Run translation tool |
| 109 | +python3 translate_repo.py |
| 110 | + |
| 111 | +# 2. Select language (e.g., 1 for English) |
| 112 | +Enter choice (1-20): 1 |
| 113 | + |
| 114 | +# 3. Confirm translation |
| 115 | +Translate 292 files to English? (y/n): y |
| 116 | + |
| 117 | +# 4. Wait for completion (progress shown for each file) |
| 118 | +[1/292] docs/java/basics/java-basic-questions-01.md |
| 119 | + → docs_en/java/basics/java-basic-questions-01.en.md |
| 120 | + Chunk 1/3... ✅ |
| 121 | + Chunk 2/3... ✅ |
| 122 | + Chunk 3/3... ✅ |
| 123 | + ✅ Translated (5234 → 6891 chars) |
| 124 | + |
| 125 | +# 5. Review and commit |
| 126 | +git add docs_en/ README.en.md |
| 127 | +git commit -m "Add English translation" |
| 128 | +git push |
| 129 | +``` |
| 130 | + |
| 131 | +## Progress Tracking |
| 132 | + |
| 133 | +The tool saves progress to `.translation_progress.json`: |
| 134 | +```json |
| 135 | +{ |
| 136 | + "completed": [ |
| 137 | + "docs/java/basics/file1.md", |
| 138 | + "docs/java/basics/file2.md" |
| 139 | + ], |
| 140 | + "failed": [] |
| 141 | +} |
| 142 | +``` |
| 143 | + |
| 144 | +If interrupted, simply run the tool again - it will skip completed files and resume where it left off. |
| 145 | + |
| 146 | +## Performance |
| 147 | + |
| 148 | +- **Speed**: ~1 file per 5-10 seconds (depending on file size) |
| 149 | +- **For JavaGuide**: 292 files ≈ 2-3 hours total |
| 150 | +- **Rate limiting**: 1 second delay between chunks to avoid throttling |
| 151 | + |
| 152 | +## Notes |
| 153 | + |
| 154 | +- ✅ Free to use (no API key required) |
| 155 | +- ✅ Preserves markdown formatting |
| 156 | +- ✅ Handles code blocks correctly |
| 157 | +- ✅ Skips existing translations |
| 158 | +- ⚠️ Review translations for accuracy (automated translation may have errors) |
| 159 | +- ⚠️ Large repos may take several hours |
| 160 | + |
| 161 | +## Contributing |
| 162 | + |
| 163 | +After running the translation tool: |
| 164 | + |
| 165 | +1. Review translated files for accuracy |
| 166 | +2. Fix any translation errors manually |
| 167 | +3. Test that links and formatting work correctly |
| 168 | +4. Create a pull request with your translations |
| 169 | + |
| 170 | +## License |
| 171 | + |
| 172 | +These tools are provided as-is for translating JavaGuide documentation. |
0 commit comments