Skip to main content

Traslate a .SRT file using any custom translator

Project description

SRTranslator

Install

PyPI

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

translator_deepl-0.2.11.tar.gz (18.4 kB view details)

Uploaded Source

Built Distribution

translator_deepl-0.2.11-py3-none-any.whl (23.4 kB view details)

Uploaded Python 3

File details

Details for the file translator_deepl-0.2.11.tar.gz.

File metadata

  • Download URL: translator_deepl-0.2.11.tar.gz
  • Upload date:
  • Size: 18.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.8

File hashes

Hashes for translator_deepl-0.2.11.tar.gz
Algorithm Hash digest
SHA256 55a8ef6ca48b0701ebb9cca9267a58ab862798f0c07f0da7abd413b6cf95de00
MD5 e46a86dad7f035cb27f9edc14e357919
BLAKE2b-256 547ebf2a77318e09652123858606c90697acae3baeec6b5d1140b748e677614b

See more details on using hashes here.

File details

Details for the file translator_deepl-0.2.11-py3-none-any.whl.

File metadata

File hashes

Hashes for translator_deepl-0.2.11-py3-none-any.whl
Algorithm Hash digest
SHA256 d1b0b304f1b9fb72b260d8fcb18c770f8a6250c302bbe8247c08de6ca378c7b4
MD5 d81dee0bd241b42ee3f3257abf5740f5
BLAKE2b-256 f935f22e83584cf58150ca39954c88506f296d6b5a848cca209d7069e68585ba

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page