144 lines
5.3 KiB
Python
Executable File
144 lines
5.3 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
|
|
from .translation_variables import code_script, code_2_language
|
|
|
|
|
|
default_script=code_script
|
|
languages = code_2_language
|
|
|
|
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 = document.add_table(rows = 1, cols = 0)
|
|
table.add_column(Inches(2.95))
|
|
table.add_column(Inches(0.30))
|
|
table.add_column(Inches(2.95))
|
|
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(2.5)
|
|
|
|
def addSpecialTerm(document, special_term):
|
|
transitions_data = document.add_paragraph(special_term)
|
|
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(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
|
|
|