
Security News
/Research
Wallet-Draining npm Package Impersonates Nodemailer to Hijack Crypto Transactions
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
enhanced-chinese-translator
Advanced tools
High-performance Chinese to English translation tool with multi-threading and batch processing
🚀 A high-performance Chinese to English translation tool with multi-threading, batch processing, and advanced optimizations for code files, documentation, and text content.
✨ 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
pip install enhanced-chinese-translator
git clone https://github.com/enhanced-translator/enhanced-chinese-translator.git
cd enhanced-chinese-translator
pip install -e .
# 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
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()
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 |
# Translate a Python file
ect my_script.py
# Translate with output to different file
ect input.py -o translated.py
# 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
# 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
from enhanced_chinese_translator import EnhancedChineseTranslator
translator = EnhancedChineseTranslator()
# Translate single text
result = translator.translate_texts_batch(["你好,世界!"])
print(result[0]) # "Hello, world!"
# 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}")
# 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")
The translator automatically detects and processes various file types:
.py
, .dart
, .js
, .ts
, .java
, .cpp
, .c
, .h
.html
, .css
, .scss
, .vue
, .jsx
, .tsx
.md
, .txt
, .rst
, .xml
, .json
, .yaml
.conf
, .ini
, .cfg
, .properties
The tool intelligently handles different contexts:
# Before
message = "用户登录失败"
# After
message = "User login failed"
# Before
# 这是一个重要的函数
def important_function():
pass
# After
# This is an important function
def important_function():
pass
// 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');
}
# 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
Create ~/.ect_config.json
:
{
"translation_service": "google",
"max_workers": 8,
"batch_size": 15,
"rate_limit": 0.03,
"backup": true,
"default_patterns": ["*.py", "*.dart", "*.js"]
}
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
API Rate Limiting
# Increase rate limit delay
ect myfile.py --rate-limit 0.1
Large File Processing
# Reduce batch size and workers
ect large_project/ --workers 3 --batch-size 5
Memory Usage
# Process files one at a time
ect project/ --workers 1 --batch-size 1
The translator includes robust error handling:
We welcome contributions! Please see our Contributing Guide for details.
git clone https://github.com/enhanced-translator/enhanced-chinese-translator.git
cd enhanced-chinese-translator
pip install -e ".[dev]"
pytest tests/
This project is licensed under the MIT License - see the LICENSE file for details.
Made with ❤️ by the Enhanced Chinese Translator Team
FAQs
High-performance Chinese to English translation tool with multi-threading and batch processing
We found that enhanced-chinese-translator demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.