Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix for monolingual docx #387

Merged
merged 1 commit into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion backend/translation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,28 @@ def convert_to_paragraph(lines):
return content


def convert_to_paragraph_monolingual(payload):
lines = []
content = ""
translated_content = ""
sentences_count = 0
number_of_paragraphs = math.ceil(len(payload) / 5)
count_paragraphs = 0
for index, segment in enumerate(payload):
if "text" in segment.keys():
lines.append(segment["target_text"])
translated_content = translated_content + " " + segment["target_text"]
sentences_count += 1
if sentences_count % 5 == 0:
count_paragraphs += 1
content = content + translated_content + "\n" + "\n"
translated_content = ""

if count_paragraphs < number_of_paragraphs:
content = content + translated_content + "\n" + "\n"
return content


def convert_to_paragraph_bilingual(payload):
lines = []
transcripted_lines = []
Expand All @@ -100,7 +122,7 @@ def convert_to_paragraph_bilingual(payload):
transcripted_content = (
transcripted_content + " " + segment["text"].replace("\n", " ")
)
translated_content = translated_content + segment["target_text"]
translated_content = translated_content + " " + segment["target_text"]
sentences_count += 1
if sentences_count % 5 == 0:
count_paragraphs += 1
Expand Down
6 changes: 2 additions & 4 deletions backend/translation/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
get_batch_translations_using_indictrans_nmt_api,
convert_to_docx,
convert_to_paragraph,
convert_to_paragraph_monolingual,
convert_to_paragraph_bilingual,
generate_translation_payload,
)
Expand Down Expand Up @@ -188,11 +189,8 @@ def export_translation(request):
filename = "translation.txt"
content = convert_to_paragraph(lines)
elif export_type == "docx":
for index, segment in enumerate(payload):
if "text" in segment.keys():
lines.append(segment["target_text"])
filename = "translation.docx"
content = convert_to_paragraph(lines)
content = convert_to_paragraph_monolingual(payload)
return convert_to_docx(content)
elif export_type == "docx-bilingual":
filename = "translation.docx"
Expand Down
Loading