Skip to content

Commit

Permalink
Fix translator returning some blank lines
Browse files Browse the repository at this point in the history
Sometimes DeepL seems to place the tags which results in a blank line, and an extra long line afterwards. This splits the long line and puts the first half in the empty line so it's all spread out again.
  • Loading branch information
ThioJoe committed Jan 20, 2024
1 parent 2572c17 commit 078822d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
21 changes: 19 additions & 2 deletions Scripts/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,25 @@ def split_and_clean_marked_combined_string(originalCombinedString, customMarkerT
if removeExtraAddedTag:
textList = [text.replace(removeExtraAddedTag, '') for text in textList]

# Remove blank lines
textList = [text for text in textList if text]
# Handle blank lines. DeepL seems to do this and sometimes combines the line after the blank line
# This will find the index of a blank line, then split the following line into approximately 2 equal parts, ensuring not to split a word by splitting at the next space near the middle
# It will put the first half into the blank line, and the second half into the next line
for i, text in enumerate(textList):
if text == '':
nextLineIndex = i + 1
while textList[nextLineIndex] == '':
nextLineIndex += 1
# Find the middle index
middle = len(textList[nextLineIndex]) // 2
# Adjust middle index to avoid splitting a word
while middle < len(textList[nextLineIndex]) and textList[nextLineIndex][middle] not in [' ', '\n']:
middle += 1
# Split the next line at the adjusted middle index
textList[i] = textList[nextLineIndex][:middle].rstrip()
textList[nextLineIndex] = textList[nextLineIndex][middle:].lstrip()

# In future may need to split line with text into however many blank lines there are plus 1 for itself


return textList

Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# License: GPLv3
# NOTE: By contributing to this project, you agree to the terms of the GPLv3 license, and agree to grant the project owner the right to also provide or sell this software, including your contribution, to anyone under any other license, with no compensation to you.

version = '0.18.0'
version = '0.18.1'
print(f"------- 'Auto Synced Translated Dubs' script by ThioJoe - Release version {version} -------")

# Import other files
Expand Down

0 comments on commit 078822d

Please sign in to comment.