A high-performance Node.js tool for translating Excel files from German to English using LibreTranslate.
- Parallel processing with optimized batch translation
- Automatic CPU and memory optimization
- Progress tracking and checkpointing
- Resume capability after interruption
- Memory-efficient processing of large files
- Intelligent error handling and retries
- Node.js (v14 or higher)
- Docker
- Excel files in the correct format
- Clone the repository:
git clone https://github.com/yourusername/excel-translator.git
cd excel-translator- Install dependencies:
npm install- Set up LibreTranslate:
docker run -d -p 5555:5000 --name libretranslate -e LT_LOAD_ONLY=de,en libretranslate/libretranslatenode --expose-gc src/index.js <excel-file> [--test] [--dry-run]Options:
--test: Process only first 10 rows (test mode)--dry-run: Estimate processing time without translating--expose-gc: Enable manual garbage collection (recommended)
The tool employs a sophisticated multi-level parallelization strategy to maximize performance while maintaining stability:
- Texts are grouped into batches based on length
- Default batch size is optimized based on CPU cores
- Adaptive batch sizing prevents memory overflow
- Configurable via
BATCH_SIZEsetting
- Multiple batches are processed concurrently
- Number of parallel batches scales with CPU cores
- Default parallel batches: 20 for 12-core systems
- Configurable via
PARALLEL_BATCHESsetting
- Each batch is split into smaller sub-batches
- Sub-batches are processed in parallel with staggered starts
- Prevents API overload while maintaining throughput
- 3 sub-batches per batch by default
- HTTP connection pooling for efficient API usage
- Keeps connections alive for better performance
- Limited to 10 concurrent sockets
- Configurable timeout settings
- Regular garbage collection
- Memory usage monitoring
- Automatic cleanup of completed batches
- Configurable memory thresholds
- Exponential backoff for retries
- Individual batch recovery
- Timeout protection
- Checkpoint system for progress preservation
The tool automatically optimizes its settings based on your system:
- Detects available CPU cores
- Adjusts parallel processing accordingly
- Special optimization for 12-core systems
- Dynamic adjustment based on system load
- Monitors available system memory
- Adjusts batch sizes based on memory
- Automatic garbage collection
- Memory-efficient data structures
- Streaming file processing
- Efficient checkpoint system
- Batched file writes
- Progress persistence
excel-translator/
├── src/
│ ├── index.js # Main application file
│ ├── config.js # Configuration and settings
│ ├── translator.js # Translation service
│ ├── checkpoint.js # Progress management
│ ├── excel.js # Excel file handling
│ └── utils.js # Utility functions
├── logs/ # Log files
├── output/ # Translated files
├── checkpoints/ # Progress checkpoints
├── package.json
└── README.md
The tool automatically configures itself based on your system resources. Key configuration options in src/config.js:
{
BATCH_SIZE: 3, // Texts per batch
PARALLEL_BATCHES: 20, // Concurrent batches
MAX_RETRIES: 5, // Retry attempts
RETRY_DELAY: 1000, // Ms between retries
BATCH_DELAY: 500, // Ms between batches
CHUNK_SIZE: 50, // Texts per chunk
MAX_TEXT_LENGTH: 5000, // Max text length
CHECKPOINT_INTERVAL: 100, // Save frequency
SAVE_INTERVAL: 1000 // Excel save frequency
}This work is licensed under the Creative Commons Attribution-NonCommercial 4.0 International License.
Due to file size limitations in Git, Excel files are not stored in the repository. Here's how to handle them:
- Place your input Excel file in the project directory
- The file will be automatically ignored by Git
- Share input files via alternative methods (Dropbox, Google Drive, etc.)
The tool generates several types of files:
-
Intermediate results (
*_translated.xlsx)- Created every 1000 rows
- Used for progress tracking
- Not stored in Git
-
Checkpoint files (
*.xlsx.checkpoint)- Contains translation progress
- Used for resuming interrupted translations
- Not stored in Git
-
Final output (
*_translated_FINAL.xlsx)- Complete translation results
- Share via file sharing services
To continue translation on a different computer:
-
Copy these files to the new computer:
- Your input Excel file
- The latest
*_translated.xlsxfile - The
.xlsx.checkpointfile - The entire project folder
-
Follow the installation steps above
-
Run the translation command with the same input file
-
The tool will automatically detect and resume from the last checkpoint
If the translation process stops:
- Check
translation.logfor errors - Verify LibreTranslate container is running:
docker ps | grep libretranslate - Restart from last checkpoint if needed
Please note that Excel files should not be committed to the repository. Use the provided .gitignore settings.