A command-line tool to translate .srt subtitle files into multiple languages (specifically Italian, Chinese, and English) using the DeepL API.
- Parses standard
.srtsubtitle files. - Automatically detects the source language of the subtitles.
- Translates text in efficient batches to respect API limits.
- Uses a
tqdmprogress bar to show translation status. - Generates a new, combined
.srtfile with all three languages for each subtitle block. - Securely loads your API key from a
.envfile.
- Language: Python 3
- Libraries:
deepl,langdetect,python-dotenv,tqdm
-
Clone the repository:
git clone https://github.com/YIN-Renlong/srt-trilingual-translator.git cd srt-trilingual-translator -
Create a virtual environment (recommended):
python3 -m venv venv source venv/bin/activate -
Install the required dependencies:
pip install -r requirements.txt
-
Set up your API Key: Create a file named
.envin the project root and add your DeepL API key:DEEPL_API_KEY="YOUR_DEEPL_API_KEY_HERE"
Run the script from your terminal, passing the path to one or more .srt files as arguments.
python3 srt_translator.py /path/to/your/file.srtFor multiple files:
python3 srt_translator.py movie1.srt movie2.srtThe script will create a new file for each input, named original-name_tri_it_zh_en-GB.srt, in the same directory.
This project is licensed under the MIT License - see the LICENSE file for details.