# Enhanced Chinese Translator
[](https://badge.fury.io/py/enhanced-chinese-translator)
[](https://pypi.org/project/enhanced-chinese-translator/)
[](https://opensource.org/licenses/MIT)
🚀 A high-performance Chinese to English translation tool with multi-threading, batch processing, and advanced optimizations for code files, documentation, and text content.
## Features
✨ **Multi-threaded Processing**: Concurrent translation with configurable worker threads
🚀 **Batch Translation**: Process multiple texts simultaneously for improved efficiency
💾 **Smart Caching**: Thread-safe translation cache to avoid duplicate API calls
🎯 **Context-Aware**: Handles strings, comments, and code contexts intelligently
⚡ **Rate Limiting**: Built-in API rate limiting to prevent service throttling
📁 **Directory Processing**: Batch process entire directories with file filtering
🔄 **Multiple Services**: Support for Google Translate, Baidu, and other services
📊 **Performance Stats**: Detailed statistics and progress tracking
🛡️ **Backup Support**: Automatic backup creation before translation
🎨 **Smart Text Processing**: Preserves programming terms and handles mixed content
## Installation
### From PyPI (Recommended)
```bash
pip install enhanced-chinese-translator
```
### From Source
```bash
git clone https://github.com/enhanced-translator/enhanced-chinese-translator.git
cd enhanced-chinese-translator
pip install -e .
```
## Quick Start
### Command Line Usage
```bash
# Translate a single file
enhanced-chinese-translator my_file.py
# Use short command alias
ect my_file.py
# Translate entire directory
ect /path/to/project --patterns "*.py" "*.dart" "*.js"
# Advanced usage with custom settings
ect /path/to/project \
--workers 10 \
--batch-size 20 \
--rate-limit 0.02 \
--output /path/to/translated \
--no-backup
```
### Python API Usage
```python
from enhanced_chinese_translator import EnhancedChineseTranslator
# Initialize translator
translator = EnhancedChineseTranslator(
translation_service='google',
max_workers=5,
batch_size=10,
rate_limit=0.05
)
# Translate a single file
success = translator.translate_file('my_file.py')
# Translate multiple files in directory
count = translator.translate_directory(
'/path/to/project',
file_patterns=['*.py', '*.dart'],
backup=True
)
# Batch translate texts
texts = ["你好世界", "这是一个测试", "中文翻译"]
translations = translator.translate_texts_batch(texts)
# Print performance statistics
translator.print_performance_stats()
```
## Command Line Options
| Option | Description | Default |
|--------|-------------|---------|
| `path` | File or directory path to translate | `.` |
| `-o, --output` | Output file/directory path | In-place |
| `-s, --service` | Translation service (`google`, `baidu`) | `google` |
| `--patterns` | File patterns to match | All text files |
| `--no-backup` | Skip creating backup files | `False` |
| `--workers` | Maximum number of worker threads | `5` |
| `--batch-size` | Batch size for translations | `10` |
| `--rate-limit` | Rate limit between API calls (seconds) | `0.05` |
## Examples
### Basic File Translation
```bash
# Translate a Python file
ect my_script.py
# Translate with output to different file
ect input.py -o translated.py
```
### Directory Translation
```bash
# Translate all Python files in current directory
ect . --patterns "*.py"
# Translate Flutter project files
ect ./lib --patterns "*.dart" --workers 8
# Translate with custom output directory
ect ./src --patterns "*.js" "*.ts" -o ./translated_src
```
### Advanced Usage
```bash
# High-performance batch translation
ect ./project \
--patterns "*.py" "*.dart" "*.js" \
--workers 15 \
--batch-size 25 \
--rate-limit 0.01 \
--output ./translated_project
# Translate without creating backups
ect ./docs --patterns "*.md" --no-backup
```
### Python API Examples
#### Basic Translation
```python
from enhanced_chinese_translator import EnhancedChineseTranslator
translator = EnhancedChineseTranslator()
# Translate single text
result = translator.translate_texts_batch(["你好,世界!"])
print(result[0]) # "Hello, world!"
```
#### Batch Processing
```python
# Process multiple texts efficiently
chinese_texts = [
"这是第一个测试文本",
"这是第二个测试文本",
"这是第三个测试文本"
]
translations = translator.translate_texts_batch(chinese_texts)
for original, translated in zip(chinese_texts, translations):
print(f"{original} -> {translated}")
```
#### Directory Processing
```python
# Translate entire project
translator = EnhancedChineseTranslator(
max_workers=10,
batch_size=20
)
success_count = translator.translate_directory(
'./my_project',
file_patterns=['*.py', '*.dart', '*.js'],
output_dir='./translated_project',
backup=True
)
print(f"Successfully translated {success_count} files")
```
## Supported File Types
The translator automatically detects and processes various file types:
- **Programming Languages**: `.py`, `.dart`, `.js`, `.ts`, `.java`, `.cpp`, `.c`, `.h`
- **Web Technologies**: `.html`, `.css`, `.scss`, `.vue`, `.jsx`, `.tsx`
- **Documentation**: `.md`, `.txt`, `.rst`, `.xml`, `.json`, `.yaml`
- **Configuration**: `.conf`, `.ini`, `.cfg`, `.properties`
## Translation Context Handling
The tool intelligently handles different contexts:
### String Literals
```python
# Before
message = "用户登录失败"
# After
message = "User login failed"
```
### Comments
```python
# Before
# 这是一个重要的函数
def important_function():
pass
# After
# This is an important function
def important_function():
pass
```
### Mixed Content
```dart
// Before
/// 获取用户信息的API接口
Future<UserInfo> getUserInfo(String userId) {
// 发送HTTP请求
return http.get('/api/user/$userId');
}
// After
/// API interface for getting user information
Future<UserInfo> getUserInfo(String userId) {
// Send HTTP request
return http.get('/api/user/$userId');
}
```
## Performance Features
### Multi-threading
- Concurrent translation processing
- Configurable worker thread count
- Thread-safe caching and rate limiting
### Batch Processing
- Group multiple texts for efficient API usage
- Reduces API call overhead
- Optimized for large-scale translations
### Smart Caching
- Persistent translation cache
- Avoids duplicate API calls
- Thread-safe cache operations
### Rate Limiting
- Prevents API service throttling
- Configurable delay between requests
- Per-thread rate limiting
## Configuration
### Environment Variables
```bash
# Set default translation service
export ECT_SERVICE=google
# Set default worker count
export ECT_WORKERS=8
# Set cache directory
export ECT_CACHE_DIR=/path/to/cache
```
### Configuration File
Create `~/.ect_config.json`:
```json
{
"translation_service": "google",
"max_workers": 8,
"batch_size": 15,
"rate_limit": 0.03,
"backup": true,
"default_patterns": ["*.py", "*.dart", "*.js"]
}
```
## Performance Statistics
The tool provides detailed performance metrics:
```
📊 Performance Statistics:
├─ Total translations: 1,247
├─ Cache hit rate: 23.4%
├─ API calls made: 89
├─ Failed translations: 0 (0.0%)
├─ Total processing time: 45.67s
└─ Average time per translation: 36.6ms
```
## Troubleshooting
### Common Issues
**API Rate Limiting**
```bash
# Increase rate limit delay
ect myfile.py --rate-limit 0.1
```
**Large File Processing**
```bash
# Reduce batch size and workers
ect large_project/ --workers 3 --batch-size 5
```
**Memory Usage**
```bash
# Process files one at a time
ect project/ --workers 1 --batch-size 1
```
### Error Handling
The translator includes robust error handling:
- Network timeout recovery
- API service fallbacks
- Partial translation recovery
- Progress preservation
## Contributing
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
### Development Setup
```bash
git clone https://github.com/enhanced-translator/enhanced-chinese-translator.git
cd enhanced-chinese-translator
pip install -e ".[dev]"
```
### Running Tests
```bash
pytest tests/
```
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## Changelog
### Version 1.0.0
- Initial release
- Multi-threaded translation processing
- Batch translation support
- Smart caching system
- Rate limiting
- Directory processing
- Performance statistics
- Multiple translation services
## Support
- 📖 [Documentation](https://github.com/jasonlau233/enhanced_chinese_translator/wiki)
- 🐛 [Issue Tracker](https://github.com/jasonlau233/enhanced_chinese_translator/issues)
- 💬 [Discussions](https://github.com/jasonlau233/enhanced_chinese_translator/discussions)
## Acknowledgments
- Thanks to all contributors who helped improve this tool
- Inspired by the need for efficient code translation workflows
- Special thanks to the open-source translation service providers
---
**Made with ❤️ by the Enhanced Chinese Translator Team**
Raw data
{
"_id": null,
"home_page": "https://github.com/jasonlau233/enhanced_chinese_translator",
"name": "enhanced-chinese-translator",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "chinese, translation, english, batch, multi-threading, concurrent, api, google, baidu",
"author": "Enhanced Chinese Translator Team",
"author_email": "Enhanced Chinese Translator Team <support@enhanced-translator.com>",
"download_url": "https://files.pythonhosted.org/packages/4d/b2/ad24a9e03fd91ef48130d7e855e0cede7e828bb7f27b163c8b17b4c6976d/enhanced_chinese_translator-1.0.1.tar.gz",
"platform": null,
"description": "# Enhanced Chinese Translator\n\n[](https://badge.fury.io/py/enhanced-chinese-translator)\n[](https://pypi.org/project/enhanced-chinese-translator/)\n[](https://opensource.org/licenses/MIT)\n\n\ud83d\ude80 A high-performance Chinese to English translation tool with multi-threading, batch processing, and advanced optimizations for code files, documentation, and text content.\n\n## Features\n\n\u2728 **Multi-threaded Processing**: Concurrent translation with configurable worker threads \n\ud83d\ude80 **Batch Translation**: Process multiple texts simultaneously for improved efficiency \n\ud83d\udcbe **Smart Caching**: Thread-safe translation cache to avoid duplicate API calls \n\ud83c\udfaf **Context-Aware**: Handles strings, comments, and code contexts intelligently \n\u26a1 **Rate Limiting**: Built-in API rate limiting to prevent service throttling \n\ud83d\udcc1 **Directory Processing**: Batch process entire directories with file filtering \n\ud83d\udd04 **Multiple Services**: Support for Google Translate, Baidu, and other services \n\ud83d\udcca **Performance Stats**: Detailed statistics and progress tracking \n\ud83d\udee1\ufe0f **Backup Support**: Automatic backup creation before translation \n\ud83c\udfa8 **Smart Text Processing**: Preserves programming terms and handles mixed content\n\n## Installation\n\n### From PyPI (Recommended)\n\n```bash\npip install enhanced-chinese-translator\n```\n\n### From Source\n\n```bash\ngit clone https://github.com/enhanced-translator/enhanced-chinese-translator.git\ncd enhanced-chinese-translator\npip install -e .\n```\n\n## Quick Start\n\n### Command Line Usage\n\n```bash\n# Translate a single file\nenhanced-chinese-translator my_file.py\n\n# Use short command alias\nect my_file.py\n\n# Translate entire directory\nect /path/to/project --patterns \"*.py\" \"*.dart\" \"*.js\"\n\n# Advanced usage with custom settings\nect /path/to/project \\\n --workers 10 \\\n --batch-size 20 \\\n --rate-limit 0.02 \\\n --output /path/to/translated \\\n --no-backup\n```\n\n### Python API Usage\n\n```python\nfrom enhanced_chinese_translator import EnhancedChineseTranslator\n\n# Initialize translator\ntranslator = EnhancedChineseTranslator(\n translation_service='google',\n max_workers=5,\n batch_size=10,\n rate_limit=0.05\n)\n\n# Translate a single file\nsuccess = translator.translate_file('my_file.py')\n\n# Translate multiple files in directory\ncount = translator.translate_directory(\n '/path/to/project',\n file_patterns=['*.py', '*.dart'],\n backup=True\n)\n\n# Batch translate texts\ntexts = [\"\u4f60\u597d\u4e16\u754c\", \"\u8fd9\u662f\u4e00\u4e2a\u6d4b\u8bd5\", \"\u4e2d\u6587\u7ffb\u8bd1\"]\ntranslations = translator.translate_texts_batch(texts)\n\n# Print performance statistics\ntranslator.print_performance_stats()\n```\n\n## Command Line Options\n\n| Option | Description | Default |\n|--------|-------------|---------|\n| `path` | File or directory path to translate | `.` |\n| `-o, --output` | Output file/directory path | In-place |\n| `-s, --service` | Translation service (`google`, `baidu`) | `google` |\n| `--patterns` | File patterns to match | All text files |\n| `--no-backup` | Skip creating backup files | `False` |\n| `--workers` | Maximum number of worker threads | `5` |\n| `--batch-size` | Batch size for translations | `10` |\n| `--rate-limit` | Rate limit between API calls (seconds) | `0.05` |\n\n## Examples\n\n### Basic File Translation\n\n```bash\n# Translate a Python file\nect my_script.py\n\n# Translate with output to different file\nect input.py -o translated.py\n```\n\n### Directory Translation\n\n```bash\n# Translate all Python files in current directory\nect . --patterns \"*.py\"\n\n# Translate Flutter project files\nect ./lib --patterns \"*.dart\" --workers 8\n\n# Translate with custom output directory\nect ./src --patterns \"*.js\" \"*.ts\" -o ./translated_src\n```\n\n### Advanced Usage\n\n```bash\n# High-performance batch translation\nect ./project \\\n --patterns \"*.py\" \"*.dart\" \"*.js\" \\\n --workers 15 \\\n --batch-size 25 \\\n --rate-limit 0.01 \\\n --output ./translated_project\n\n# Translate without creating backups\nect ./docs --patterns \"*.md\" --no-backup\n```\n\n### Python API Examples\n\n#### Basic Translation\n\n```python\nfrom enhanced_chinese_translator import EnhancedChineseTranslator\n\ntranslator = EnhancedChineseTranslator()\n\n# Translate single text\nresult = translator.translate_texts_batch([\"\u4f60\u597d\uff0c\u4e16\u754c\uff01\"])\nprint(result[0]) # \"Hello, world!\"\n```\n\n#### Batch Processing\n\n```python\n# Process multiple texts efficiently\nchinese_texts = [\n \"\u8fd9\u662f\u7b2c\u4e00\u4e2a\u6d4b\u8bd5\u6587\u672c\",\n \"\u8fd9\u662f\u7b2c\u4e8c\u4e2a\u6d4b\u8bd5\u6587\u672c\", \n \"\u8fd9\u662f\u7b2c\u4e09\u4e2a\u6d4b\u8bd5\u6587\u672c\"\n]\n\ntranslations = translator.translate_texts_batch(chinese_texts)\nfor original, translated in zip(chinese_texts, translations):\n print(f\"{original} -> {translated}\")\n```\n\n#### Directory Processing\n\n```python\n# Translate entire project\ntranslator = EnhancedChineseTranslator(\n max_workers=10,\n batch_size=20\n)\n\nsuccess_count = translator.translate_directory(\n './my_project',\n file_patterns=['*.py', '*.dart', '*.js'],\n output_dir='./translated_project',\n backup=True\n)\n\nprint(f\"Successfully translated {success_count} files\")\n```\n\n## Supported File Types\n\nThe translator automatically detects and processes various file types:\n\n- **Programming Languages**: `.py`, `.dart`, `.js`, `.ts`, `.java`, `.cpp`, `.c`, `.h`\n- **Web Technologies**: `.html`, `.css`, `.scss`, `.vue`, `.jsx`, `.tsx`\n- **Documentation**: `.md`, `.txt`, `.rst`, `.xml`, `.json`, `.yaml`\n- **Configuration**: `.conf`, `.ini`, `.cfg`, `.properties`\n\n## Translation Context Handling\n\nThe tool intelligently handles different contexts:\n\n### String Literals\n```python\n# Before\nmessage = \"\u7528\u6237\u767b\u5f55\u5931\u8d25\"\n\n# After \nmessage = \"User login failed\"\n```\n\n### Comments\n```python\n# Before\n# \u8fd9\u662f\u4e00\u4e2a\u91cd\u8981\u7684\u51fd\u6570\ndef important_function():\n pass\n\n# After\n# This is an important function \ndef important_function():\n pass\n```\n\n### Mixed Content\n```dart\n// Before\n/// \u83b7\u53d6\u7528\u6237\u4fe1\u606f\u7684API\u63a5\u53e3\nFuture<UserInfo> getUserInfo(String userId) {\n // \u53d1\u9001HTTP\u8bf7\u6c42\n return http.get('/api/user/$userId');\n}\n\n// After\n/// API interface for getting user information\nFuture<UserInfo> getUserInfo(String userId) {\n // Send HTTP request\n return http.get('/api/user/$userId');\n}\n```\n\n## Performance Features\n\n### Multi-threading\n- Concurrent translation processing\n- Configurable worker thread count\n- Thread-safe caching and rate limiting\n\n### Batch Processing \n- Group multiple texts for efficient API usage\n- Reduces API call overhead\n- Optimized for large-scale translations\n\n### Smart Caching\n- Persistent translation cache\n- Avoids duplicate API calls\n- Thread-safe cache operations\n\n### Rate Limiting\n- Prevents API service throttling\n- Configurable delay between requests \n- Per-thread rate limiting\n\n## Configuration\n\n### Environment Variables\n\n```bash\n# Set default translation service\nexport ECT_SERVICE=google\n\n# Set default worker count\nexport ECT_WORKERS=8\n\n# Set cache directory\nexport ECT_CACHE_DIR=/path/to/cache\n```\n\n### Configuration File\n\nCreate `~/.ect_config.json`:\n\n```json\n{\n \"translation_service\": \"google\",\n \"max_workers\": 8,\n \"batch_size\": 15,\n \"rate_limit\": 0.03,\n \"backup\": true,\n \"default_patterns\": [\"*.py\", \"*.dart\", \"*.js\"]\n}\n```\n\n## Performance Statistics\n\nThe tool provides detailed performance metrics:\n\n```\n\ud83d\udcca Performance Statistics:\n \u251c\u2500 Total translations: 1,247\n \u251c\u2500 Cache hit rate: 23.4%\n \u251c\u2500 API calls made: 89\n \u251c\u2500 Failed translations: 0 (0.0%)\n \u251c\u2500 Total processing time: 45.67s\n \u2514\u2500 Average time per translation: 36.6ms\n```\n\n## Troubleshooting\n\n### Common Issues\n\n**API Rate Limiting**\n```bash\n# Increase rate limit delay\nect myfile.py --rate-limit 0.1\n```\n\n**Large File Processing**\n```bash\n# Reduce batch size and workers\nect large_project/ --workers 3 --batch-size 5\n```\n\n**Memory Usage**\n```bash\n# Process files one at a time\nect project/ --workers 1 --batch-size 1\n```\n\n### Error Handling\n\nThe translator includes robust error handling:\n- Network timeout recovery\n- API service fallbacks \n- Partial translation recovery\n- Progress preservation\n\n## Contributing\n\nWe welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.\n\n### Development Setup\n\n```bash\ngit clone https://github.com/enhanced-translator/enhanced-chinese-translator.git\ncd enhanced-chinese-translator\npip install -e \".[dev]\"\n```\n\n### Running Tests\n\n```bash\npytest tests/\n```\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## Changelog\n\n### Version 1.0.0\n- Initial release\n- Multi-threaded translation processing\n- Batch translation support\n- Smart caching system\n- Rate limiting\n- Directory processing\n- Performance statistics\n- Multiple translation services\n\n## Support\n\n- \ud83d\udcd6 [Documentation](https://github.com/jasonlau233/enhanced_chinese_translator/wiki)\n- \ud83d\udc1b [Issue Tracker](https://github.com/jasonlau233/enhanced_chinese_translator/issues)\n- \ud83d\udcac [Discussions](https://github.com/jasonlau233/enhanced_chinese_translator/discussions)\n\n## Acknowledgments\n\n- Thanks to all contributors who helped improve this tool\n- Inspired by the need for efficient code translation workflows\n- Special thanks to the open-source translation service providers\n\n---\n\n**Made with \u2764\ufe0f by the Enhanced Chinese Translator Team**\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "High-performance Chinese to English translation tool with multi-threading and batch processing",
"version": "1.0.1",
"project_urls": {
"Bug Reports": "https://github.com/jasonlau233/enhanced_chinese_translator/issues",
"Documentation": "https://github.com/jasonlau233/enhanced_chinese_translator/wiki",
"Homepage": "https://github.com/jasonlau233/enhanced_chinese_translator",
"Source": "https://github.com/jasonlau233/enhanced_chinese_translator"
},
"split_keywords": [
"chinese",
" translation",
" english",
" batch",
" multi-threading",
" concurrent",
" api",
" google",
" baidu"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "c51f29569ac079b581f726fefe9e2ce041769175cabbfb4af430648a8bf3d13c",
"md5": "b55ffebb6016be954bbc70289fd027bc",
"sha256": "b04a14117ab110eec500be568d4db899044616d43b78d8f9f2b8f08a84eeecbf"
},
"downloads": -1,
"filename": "enhanced_chinese_translator-1.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "b55ffebb6016be954bbc70289fd027bc",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 15064,
"upload_time": "2025-07-23T07:16:52",
"upload_time_iso_8601": "2025-07-23T07:16:52.754393Z",
"url": "https://files.pythonhosted.org/packages/c5/1f/29569ac079b581f726fefe9e2ce041769175cabbfb4af430648a8bf3d13c/enhanced_chinese_translator-1.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "4db2ad24a9e03fd91ef48130d7e855e0cede7e828bb7f27b163c8b17b4c6976d",
"md5": "4879a9c26e58ded1b157380c15a48db3",
"sha256": "f668f0da7f4a646aeaf60f228aab66466cc47f8369589c30ecd25267e88932cf"
},
"downloads": -1,
"filename": "enhanced_chinese_translator-1.0.1.tar.gz",
"has_sig": false,
"md5_digest": "4879a9c26e58ded1b157380c15a48db3",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 19135,
"upload_time": "2025-07-23T07:16:54",
"upload_time_iso_8601": "2025-07-23T07:16:54.355440Z",
"url": "https://files.pythonhosted.org/packages/4d/b2/ad24a9e03fd91ef48130d7e855e0cede7e828bb7f27b163c8b17b4c6976d/enhanced_chinese_translator-1.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-23 07:16:54",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "jasonlau233",
"github_project": "enhanced_chinese_translator",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "requests",
"specs": [
[
">=",
"2.25.0"
]
]
}
],
"lcname": "enhanced-chinese-translator"
}