Skip to content

Commit

Permalink
better formatting of translated segments
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusbach committed Sep 15, 2023
1 parent 455e563 commit 24fe8c9
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions translate_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ async def run_translate(index, chunk, lang):
return subs

# Async chunk translate function


async def translate_chunk(index, chunk, target_lang):
while True:
try:
Expand Down Expand Up @@ -149,15 +147,15 @@ def unjoin_sentences(original_sentence: str, modified_sentence: str, separator:
# fix strange formatation returned by google translate, case occuring
modified_sentence.replace(f"{separator_unjoin} ", f"{separator_unjoin}").replace(f" {separator_unjoin}", f"{separator_unjoin}").replace(f"{separator_unjoin}.", f".{separator_unjoin}").replace(f"{separator_unjoin},", f",{separator_unjoin}")

# split by separator, remove double spaces and empty or only space strings strings from list
# split by separator, remove double spaces and empty or only space strings from list
original_lines = original_sentence.split(separator)
original_lines = [s.strip().replace(' ', ' ')
original_lines = [s.strip().replace(' ', ' ').lstrip(" ,.:;)")
for s in original_lines if s.strip()]
original_lines = [s for s in original_lines if s]
original_lines = [s for s in original_lines if s.strip()]
# split by separator, remove double spaces and empty or only space strings from list
modified_lines = modified_sentence.split(separator_unjoin)
modified_lines = [s.strip().replace(' ', ' ')
modified_lines = [s.strip().replace(' ', ' ').lstrip(" ,.:;)")
for s in modified_lines if s.strip()]
modified_lines = [s for s in modified_lines if s]
modified_lines = [s for s in modified_lines if s.strip()]
Expand Down

0 comments on commit 24fe8c9

Please sign in to comment.