Skip to content

Commit 078822d

Browse files
committed
Fix translator returning some blank lines
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.
1 parent 2572c17 commit 078822d

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

Scripts/translate.py

+19-2
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,25 @@ def split_and_clean_marked_combined_string(originalCombinedString, customMarkerT
153153
if removeExtraAddedTag:
154154
textList = [text.replace(removeExtraAddedTag, '') for text in textList]
155155

156-
# Remove blank lines
157-
textList = [text for text in textList if text]
156+
# Handle blank lines. DeepL seems to do this and sometimes combines the line after the blank line
157+
# 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
158+
# It will put the first half into the blank line, and the second half into the next line
159+
for i, text in enumerate(textList):
160+
if text == '':
161+
nextLineIndex = i + 1
162+
while textList[nextLineIndex] == '':
163+
nextLineIndex += 1
164+
# Find the middle index
165+
middle = len(textList[nextLineIndex]) // 2
166+
# Adjust middle index to avoid splitting a word
167+
while middle < len(textList[nextLineIndex]) and textList[nextLineIndex][middle] not in [' ', '\n']:
168+
middle += 1
169+
# Split the next line at the adjusted middle index
170+
textList[i] = textList[nextLineIndex][:middle].rstrip()
171+
textList[nextLineIndex] = textList[nextLineIndex][middle:].lstrip()
172+
173+
# In future may need to split line with text into however many blank lines there are plus 1 for itself
174+
158175

159176
return textList
160177

main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# License: GPLv3
77
# 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.
88

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

1212
# Import other files

0 commit comments

Comments
 (0)