Skip to content

fstasel/srt_translate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

📂 srt_translate

📝 Project Overview

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.


🧠 Features

✅ 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.)


⚙️ Installation

1️⃣ Clone the Repository

git clone https://github.com/fstasel/srt_translate.git
cd srt_translate

2️⃣ Ensure Python 3.8+

Check your Python version:

python3 --version

3️⃣ Make the script executable (optional)

chmod +x srt_translate.py

🧩 Dependencies

This tool only uses Python standard library (no extra packages needed):

  • argparse
  • logging
  • urllib
  • json
  • re
  • sys

🚀 Usage

Basic command

python3 srt_translate.py --model mistral --target-lang Turkish -i movie.srt -o movie_tr.srt

This will:

  1. Detect the input language automatically
  2. Summarize and extract translation directives
  3. Translate the entire subtitle set to Turkish
  4. Save result as movie_tr.srt

Full command reference

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 Levels

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 ...

🧪 Example

python3 srt_translator.py   --model llama3   --target-lang English   -i drama_original.srt   -o drama_english.srt   -vv

Example 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.

🧰 Repository Structure

srt_translator/
├── srt_translator.py       # Main script
├── README.md               # This file
└── LICENSE                 # MIT License

📜 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.

🧑‍💻 Contributing

Contributions are welcome!
If you’d like to improve the translation logic, add caching, or integrate other LLM APIs, please submit a pull request.


⭐ If you find srt_translate useful, give it a star on GitHub!

About

Subtitle file (.srt) translator

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages