Init
This commit is contained in:
33
AutoTrans.py
Normal file
33
AutoTrans.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import ass
|
||||
import os
|
||||
|
||||
from utils.preprocessing import replace_english_words, remove_ass_statements, remove_new_line_statements, split_sentence
|
||||
from utils.translator import translator
|
||||
|
||||
LANGUAGES_DICT = {
|
||||
'deu': 'de',
|
||||
'spa': 'es',
|
||||
'fra': 'fr',
|
||||
'hin': 'hi',
|
||||
'por': 'pt',
|
||||
'rus': 'ru'
|
||||
}
|
||||
|
||||
INPUT_FILE = os.path.join('1-Input', 'eng.ass')
|
||||
|
||||
for lang in list(LANGUAGES_DICT.keys()):
|
||||
# Read ass file
|
||||
|
||||
ass_file = open(INPUT_FILE, 'r', encoding='utf_8_sig')
|
||||
ass_doc = ass.parse(ass_file)
|
||||
|
||||
# Parse subtitles
|
||||
for event in ass_doc.events:
|
||||
event.text = remove_ass_statements(event.text)
|
||||
event.text = remove_new_line_statements(event.text)
|
||||
event.text = replace_english_words(event.text)
|
||||
event.text = translator(event.text, lang)
|
||||
|
||||
out_file = os.path.join('2-Output', f'{LANGUAGES_DICT[lang]}.ass')
|
||||
with open(out_file, 'w', encoding='utf_8_sig') as output_file:
|
||||
ass_doc.dump_file(output_file)
|
Reference in New Issue
Block a user