161 lines
8.2 KiB
Python
Executable File
161 lines
8.2 KiB
Python
Executable File
from docx.shared import Inches, Cm, Pt
|
|
from docx.enum.text import WD_ALIGN_PARAGRAPH
|
|
from docx.enum.table import WD_TABLE_ALIGNMENT, WD_ALIGN_VERTICAL
|
|
|
|
default_script={"hi": "Devanagari", "en": "Latin","ur":"Arabic" ,"ar": "Arabic", "kn": "Kannada", 'ta':'Tamil', 'bg': 'Cyrillic',
|
|
'bn':'Bengali', 'te':'Telugu','ml':'Malayalam', 'ru':'Cyrillic', 'sr':'Cyrillic', 'uk':'Cyrillic', 'hr': 'Cyrillic',
|
|
'ga': 'Latin', 'sq': "Latin",'mr':'Devanagari', 'fa':'Arabic', 'tr': 'Latin', 'hu': 'Latin', 'it': "Latin", 'ro':'Latin',
|
|
'pa':'Gurmukhi','gu':'Gujarati','or':'Odia','zh-CN':'Hanji', 'zh-TW':'Hanji', 'ne':'Devanagri','fr':'Latin','es':'Latin','id':'Latin',
|
|
'el':'Latin','ja':'Kana','jv':'Javanese','ko':'Hangul','be':'Cyrillic','uz':'Cyrillic','sd':'Arabic','af':'Latin',
|
|
'de':'Latin','is':'Latin','ig':'Latin','la':'Latin','pt':'Latin','my':'Burmese','th':'Thai','su':'Sundanese','lo':'Lao',
|
|
'am':'amharic','si':'sinhala','az':'Cyrillic','kk':'Cyrillic','mk':'Cyrillic','bs':'Cyrillic','ps':'Arabic','mg':'Latin',
|
|
'ms':'Latin','yo':'Arabic','cs':'Latin','da':'Latin','nl':'Latin','tl':'Latin','no':'Latin','sl':'Latin','sv':'Latin',
|
|
'vi':'Latin','cy':'Latin','he':'Hebrew','hy':'Armenian','km':'Khmer','ka':'Georgian','mn':'Mongolian','ku':'Latin',
|
|
'ky':'Cyrillic','tk':'Latin','fi':'Latin','ht':'Latin','haw':'Latin','lt':'Latin','lb':'Latin','mt':'Latin','pl':'Latin',
|
|
'eo':'Latin','tt':'Cyrillic','ug':'Arabic','ha':'Latin','so':'Latin','sw':'Latin','yi':'Latin','eu':'Latin','ca':'Latin',
|
|
'ceb':'Latin','co':'Latin','et':'Latin','fy':'Latin','gl':'Latin','hmn':'Latin','rw':'Latin','lv':'Latin',
|
|
'mi':'Latin','sm':'Latin','gd':'Latin','st':'Latin','sn':'Latin','sk':'Latin','xh':'Latin','zu':'Latin'}
|
|
|
|
|
|
languages = {'hi': 'Hindi', 'en': 'English','te':'Telugu', 'ur': 'Urdu','ar':'Arabic', 'kn':'Kannada', 'ta': 'Tamil', 'bg': 'Bulgarian', 'bn': 'Bengali',
|
|
'ml': 'Malayalam', 'ru': 'Russian', 'sr': 'Serbian', 'uk': 'Ukranian', 'hr': 'Croatian', 'ga': 'Irish','sq': 'Albanian',
|
|
'mr': 'Marathi', 'fa':'Persian','tr':'Turkish','hu':'Hungarian','it':'Italian','ro':'Romanian','pa':'Punjabi','gu':'Gujrati',
|
|
'or':'Odia','zh':'Chienese','ne':'Nepali','fr':'French','es':'Spanish','id':'Indonesian','el':'Greek','ja':'Japanese',
|
|
'jv':'Javanese','ko':'Korean','be':'Belarusian','uz':'Uzbek','sd':'Sindhi','af':'Afrikaans','de':'German','is':'Icelandic',
|
|
'ig':'Igbo','la':'Latin','pt':'Portugese','my':'Mayanmar','th':'Thai','su':'Sundanese','lo':'Lao','am':'amharic','si':'sinhala',
|
|
'az':'azerbaijani ','kk':'Kazak','mk':'Macedonian','bs':'Bosnian','ps':'Pashto','mg':'Malagasy','ms':'Malay','yo':'Yoruba',
|
|
'cs':'Czech','da':'Danish','nl':'Dutch','tl':'Tagalog','no':'Norwegian','sl':'Slovenian','sv':' Swedish','vi':'Vietnamese','cy':'Welsh',
|
|
'he':'Hebrew','hy':'Armenian','km':'Khmer','ka':'Georgian','mn':'Mongolian','ku':'Kurdish','ky':'Kyrgyz','tk':'Turkmen',
|
|
'fi':'Finnish','ht':'Haitian Creole','haw':'Hawaiian','lt':'Lithuanian','lb':'Luxembourgish','mt':'Maltese','pl':'Polish',
|
|
'eo':'Esperanto','tt':'Tatar','ug':'Uyghur','ha':'Hausa','so':'Somali','sw':'Swahili','yi':'Yiddish','eu':'Basque','ca':'Catalan',
|
|
'ceb':'Cebuano','co':'Corsican','et':'Estonian','fy':'Frisian','gl':'Galician','hmn':'Hmong','rw':'Kinyarwanda','lv':'Latvian',
|
|
'mi':'Maori','sm':'Samoan','gd':'Scots Gaelic','st':'Sesotho','sn':'Shona','sk':'Slovak','xh':'Xhosa','zu':'Zulu'}
|
|
|
|
|
|
|
|
|
|
|
|
def addSlugLine(document, slugline):
|
|
slug_data = document.add_paragraph()
|
|
slug_data_format = slug_data.paragraph_format
|
|
slug_data_format.space_after = Pt(12)
|
|
slug_data_format.keep_with_next = True
|
|
slug_data_format.left_indent = Inches(0)
|
|
slug_data.style.font.name = 'Courier New'
|
|
slug_data.style.font.size = Pt(12.0)
|
|
slug_data.add_run(slugline).bold = True
|
|
|
|
def addActionLine(document,actionline, non_dial_dest_lang):
|
|
act = document.add_paragraph()
|
|
act_format = act.paragraph_format
|
|
act_format.space_after = Pt(12)
|
|
act_format.alignment = WD_ALIGN_PARAGRAPH.JUSTIFY
|
|
act_format.line_spacing = Pt(12)
|
|
act_format.left_indent = Inches(0)
|
|
if (non_dial_dest_lang == 'hi') or (non_dial_dest_lang =='gu'):
|
|
act.style.font.name = 'Mangal'
|
|
else:
|
|
act.style.font.name = 'Courier New'
|
|
act.add_run(actionline)
|
|
|
|
def addSpeaker(document,speaker):
|
|
spk = document.add_paragraph(speaker)
|
|
spk.style.font.name = 'Courier New'
|
|
spk_format = spk.paragraph_format
|
|
spk_format.keep_with_next = True
|
|
spk_format.space_after = 0
|
|
spk_format.line_spacing = Pt(12)
|
|
spk_format.left_indent = Inches(2.0)
|
|
|
|
def addParenthetical(document,parenthetical):
|
|
parathetical = document.add_paragraph(parenthetical)
|
|
parathetical.style.font.name = 'Courier New'
|
|
parathetical_format = parathetical.paragraph_format
|
|
parathetical_format.keep_with_next = True
|
|
parathetical_format.space_after = 0
|
|
parathetical_format.line_spacing = Pt(12)
|
|
parathetical_format.alignment = WD_ALIGN_PARAGRAPH.JUSTIFY
|
|
parathetical_format.left_indent = Inches(1.5)
|
|
parathetical_format.right_indent = Inches(1.5)
|
|
|
|
def addDialogue(document, dialogue, dial_dest_lang):
|
|
dia = document.add_paragraph(dialogue)
|
|
dia_format = dia.paragraph_format
|
|
dia_format.keep_together = True
|
|
dia_format.space_after = Pt(12)
|
|
dia_format.alignment = WD_ALIGN_PARAGRAPH.JUSTIFY
|
|
dia_format.line_spacing = Pt(12)
|
|
dia_format.left_indent = Inches(1)
|
|
dia_format.right_indent = Inches(1.25)
|
|
if (dial_dest_lang =='hi'):
|
|
dia.style.font.name = 'Mangal'
|
|
else:
|
|
dia.style.font.name = 'Courier New'
|
|
|
|
def dual_script(document, orignal_dial, translated_dial, dial_dest_lang):
|
|
table = document.add_table(rows = 1, cols = 3)
|
|
table.alignment = WD_TABLE_ALIGNMENT.CENTER
|
|
table.autofit = False
|
|
table.space_before = Pt(10)
|
|
table.allow_autofit = False
|
|
table.rows[0].cells[0].width = Inches(3.75)
|
|
table.rows[0].cells[1].width = Inches(.30)
|
|
table.rows[0].cells[0].vertical_alignment = WD_ALIGN_VERTICAL.TOP
|
|
|
|
col1 = table.rows[0].cells
|
|
dialogue1 = col1[0].paragraphs[0]
|
|
dialogue1.add_run(orignal_dial)
|
|
dia_format1 = dialogue1.paragraph_format
|
|
dia_format1.space_before = Pt(5)
|
|
table.rows[0].cells[2].width = Inches(3.75)
|
|
col3 = table.rows[0].cells
|
|
|
|
dialogue2 = col3[2].paragraphs[0]
|
|
dialogue2.add_run(translated_dial)
|
|
dia_format2 = dialogue2.paragraph_format
|
|
dia_format2.space_before = Pt(5)
|
|
if (dial_dest_lang =='hi'):
|
|
dialogue2.style.font.name = 'Mangal'
|
|
else:
|
|
dialogue2.style.font.name = 'Courier New'
|
|
|
|
def addTransition(document,transition):
|
|
transitions_data = document.add_paragraph(transition)
|
|
transitions_data_format = transitions_data.paragraph_format
|
|
transitions_data_format.space_after = Pt(12)
|
|
transitions_data_format.keep_with_next = True
|
|
transitions_data_format.left_indent = Inches(5.0)
|
|
|
|
# def dial_checker(dial_dest_lang, dial_src_lang, dial_dest_script, dial_src_script ):
|
|
# if( dial_dest_lang != dial_src_lang ):
|
|
# dial_translate = True
|
|
# if ( dial_dest_script != default_script[dial_dest_lang]):
|
|
# dial_transliterate = True
|
|
# else:
|
|
# dial_transliterate = False
|
|
# else:
|
|
# dial_translate = False
|
|
|
|
# if dial_translate == False:
|
|
# if ( dial_dest_script != dial_src_script ):
|
|
# dial_transliterate = True
|
|
# else:
|
|
# dial_transliterate = False
|
|
# return dial_translate, dial_transliterate
|
|
|
|
def dial_checker(dial_dest_lang, dial_src_lang):
|
|
if( dial_dest_lang != dial_src_lang ):
|
|
dial_translate = True
|
|
else:
|
|
dial_translate = False
|
|
|
|
return dial_translate
|
|
|
|
def non_dial_checker( non_dial_dest_lang, non_dial_src_lang ):
|
|
if( non_dial_dest_lang != non_dial_src_lang ):
|
|
non_dial_translate = True
|
|
else:
|
|
non_dial_translate=False
|
|
return non_dial_translate
|
|
|