srt_translate is a command-line tool for translating SRT subtitle files using a local Ollama LLM server.
It automatically detects the source language, extracts translation directives (e.g., tone, style, or names not to translate), and produces a fully translated .srt file while preserving original timestamps and formatting.
It’s ideal for translating movie, TV show, or documentary subtitles without breaking SRT structure.
✅ Automatically detects input subtitle language
✅ Summarizes content to provide context for better translation
✅ Extracts translation directives (e.g., proper nouns, tone, cultural hints)
✅ Preserves SRT indexes and timestamps
✅ Segments subtitles for efficient and consistent translation
✅ Adjustable verbosity levels (see below)
✅ Works with any Ollama-supported LLM model (e.g. mistral, llama3, phi3, etc.)
git clone https://github.com/fstasel/srt_translate.git
cd srt_translateCheck your Python version:
python3 --versionchmod +x srt_translate.pyThis tool only uses Python standard library (no extra packages needed):
argparseloggingurllibjsonresys
python3 srt_translate.py --model mistral --target-lang Turkish -i movie.srt -o movie_tr.srtThis will:
- Detect the input language automatically
- Summarize and extract translation directives
- Translate the entire subtitle set to Turkish
- Save result as
movie_tr.srt
| Option | Description |
|---|---|
--input, -i |
Input SRT file (default: stdin) |
--output, -o |
Output SRT file (default: stdout) |
--ollama-host |
Ollama server host:port (default: localhost:11434) |
--model |
Model name on Ollama (e.g., mistral, llama3, phi3) |
--target-lang |
Target translation language (e.g., English, Spanish, Turkish) |
--segment-size |
Number of subtitle blocks to translate per request (default: 20) |
--char-limit |
Number of characters used for summary/context (default: 2000) |
--verbosity, -v |
Increase logging verbosity (-v, -vv, -vvv) |
| Verbosity | Description | Example Usage |
|---|---|---|
| Default | Only errors printed | (no -v) |
-v |
Show warnings | python3 srt_translator.py -v ... |
-vv |
Show info logs | python3 srt_translator.py -vv ... |
-vvv |
Full debug (includes full JSON input/output) | python3 srt_translator.py -vvv ... |
python3 srt_translator.py --model llama3 --target-lang English -i drama_original.srt -o drama_english.srt -vvExample log output:
2025-11-10 12:23:14,784 [INFO] Extracted 153 subtitle blocks.
2025-11-10 12:23:15,002 [INFO] Detected input language: Japanese
2025-11-10 12:23:20,314 [INFO] Translation directives: Maintain character tone, do not translate "Sensei".
2025-11-10 12:23:27,817 [INFO] Translation completed successfully.
srt_translator/
├── srt_translator.py # Main script
├── README.md # This file
└── LICENSE # MIT License
MIT License
MIT License
Copyright (c) 2025 Faris Serdar TAŞEL
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Contributions are welcome!
If you’d like to improve the translation logic, add caching, or integrate other LLM APIs, please submit a pull request.