Traslate a .SRT file using any custom translator
Project description
SRTranslator
Install
pip install srtranslator
Usage in Blender
tin2tin has made this blender addon. Check it out.
Usage from script
Import stuff
import os
# SRT File
from srtranslator import SrtFile
# ASS File
from srtranslator import AssFile
from srtranslator.translators.deepl_api import DeeplApi
from srtranslator.translators.deepl_scrap import DeeplTranslator
from srtranslator.translators.translatepy import TranslatePy
from srtranslator.translators.pydeeplx import PyDeepLX
Initialize translator. It can be any translator, even your own, check the docs, there are instructions per translator and how to create your own.
translator = DeeplTranslator() # or TranslatePy() or DeeplApi(api_key) or DeepLX()
Load, translate and save. For multiple recursive files in folder, check examples folder
filepath = "./filepath/to/srt"
# SRT File
sub = SrtFile(filepath)
# ASS File
sub = AssFile(filepath)
# Translate
sub.translate(translator, "en", "es")
# Making the result subtitles prettier
sub.wrap_lines()
sub.save(f"{os.path.splitext(filepath)[0]}_translated.srt")
Quit translator
translator.quit()
Usage from GUI
Last release has installers for the official srtranslatorGUI on windows (.msi) and linux (.deb, .flatpak)
Package from source
In folder srtranslatorGUI there is a briefcase/toga GUI implementation in top of the translator core. You could create your own binary with:
cd srtranslatorGUI
pip install briefcase
briefcase create
briefcase build
briefcase package
Binaries found in dist
folder
Alternatives
KryptoST has made a graphical user interface. You can check it out here
Usage command line
# SRT file
python -m srtranslator ./filepath/to/srt -i SRC_LANG -o DEST_LANG
# ASS file
python -m srtranslator ./filepath/to/ass -i SRC_LANG -o DEST_LANG
Advanced usage
usage: __main__.py [-h] [-i SRC_LANG] [-o DEST_LANG] [-v] [-vv] [-s] [-w WRAP_LIMIT] [-t {deepl-scrap,translatepy,deepl-api,pydeeplx}] [--auth AUTH] path
Translate an .STR and .ASS file
positional arguments:
path File to translate
options:
-h, --help show this help message and exit
-i SRC_LANG, --src-lang SRC_LANG
Source language. Default: auto
-o DEST_LANG, --dest-lang DEST_LANG
Destination language. Default: es (spanish)
-v, --verbose Increase output verbosity
-vv, --debug Increase output verbosity for debugging
-s, --show-browser Show browser window
-w WRAP_LIMIT, --wrap-limit WRAP_LIMIT
Number of characters -including spaces- to wrap a line of text. Default: 50
-t {deepl-scrap,translatepy,deepl-api}, --translator {deepl-scrap,translatepy,deepl-api,pydeeplx}
Built-in translator to use
--auth AUTH Api key if needed on translator
--proxies Use proxy by default for pydeeplx
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file srtranslator-0.3.8.tar.gz
.
File metadata
- Download URL: srtranslator-0.3.8.tar.gz
- Upload date:
- Size: 12.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 53546e1fc040c005132b86b7ebf16fad158cc4511b39ffa95f3a59319c22f09b |
|
MD5 | c5a4ce1a50b3dbaadbcb950e76756d71 |
|
BLAKE2b-256 | b2580f147facf2f7510207e298ca69ddaa925e0aa298d1b33ac6bc666213b24a |
File details
Details for the file srtranslator-0.3.8-py3-none-any.whl
.
File metadata
- Download URL: srtranslator-0.3.8-py3-none-any.whl
- Upload date:
- Size: 15.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3676f9fa6664c3f58fc5031e20ce034573870dbf8f4cf3e87c3530dfcfb5db16 |
|
MD5 | 83b51fb4521e54c9841f3bac82b0ecd0 |
|
BLAKE2b-256 | b1a94cd36e0a81b5d531d3b83bb5008fcf5dee8c361536562d631bf5a287bbbd |