Skip to content

Instantly share code, notes, and snippets.

Last active Jun 18, 2020
What would you like to do?
Quick and dirty .srt file translation using cheeseshop packages translate, funcy
import sys
import srt
from translate import Translator
import funcy as fy
codec = 'ISO-8859-1'
tr = Translator('sv', email='your.adress@provider.x')
inf = sys.argv[-1]
outf = f"{inf.split('.srt')[0]}"
translated = ()
with open(sys.argv[-1], encoding=codec) as fp:
texts = srt.parse(
out = open(outf, encoding=codec)
translated = srt.parse(
resume = fy.last(translated).index
out = open(outf, 'a')
except IOError:
out = open(outf, 'w', encoding=codec)
resume = 0
for text in texts:
if text.index > resume:
sv = tr.translate(text.content)
print(f"TEXT {text.index}, {sv}")
out.write(text.to_srt().replace(text.content, sv))
resume += 1
print(f"{inf} translation done.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment