summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormorpheus65535 <[email protected]>2022-01-18 18:53:57 -0500
committermorpheus65535 <[email protected]>2022-01-18 18:53:57 -0500
commit391892fdf0450cb30c6ce95ff0c006f6bcaf5a8f (patch)
treefae812e8c5f75814dc060b6e30f577fcc454c5c4
parent28663a69379d99876547c652ee8e87416e8e6b90 (diff)
downloadbazarr-391892fdf0450cb30c6ce95ff0c006f6bcaf5a8f.tar.gz
bazarr-391892fdf0450cb30c6ce95ff0c006f6bcaf5a8f.zip
Fixed translation issue when first line is an empty string. #1672v1.0.3-beta.13
-rw-r--r--bazarr/utils.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/bazarr/utils.py b/bazarr/utils.py
index 0a41d32d3..6a3cf8951 100644
--- a/bazarr/utils.py
+++ b/bazarr/utils.py
@@ -480,6 +480,11 @@ def translate_subtitles_file(video_path, source_srt_file, to_lang, forced, hi):
logging.debug('BAZARR is sending {} blocks to Google Translate'.format(len(lines_block_list)))
for block_str in lines_block_list:
+ empty_first_line = False
+ if block_str.startswith('\n\n\n'):
+ # This happens when the first line of text in a subtitles file is an empty string
+ empty_first_line = True
+
try:
translated_partial_srt_text = GoogleTranslator(source='auto',
target=language_code_convert_dict.get(lang_obj.alpha2,
@@ -489,6 +494,9 @@ def translate_subtitles_file(video_path, source_srt_file, to_lang, forced, hi):
logging.exception(f'BAZARR Unable to translate subtitles {source_srt_file}')
return False
else:
+ if empty_first_line:
+ # GoogleTranslate remove new lines at the beginning of the string, so we add it back.
+ translated_partial_srt_text = '\n\n\n' + translated_partial_srt_text
translated_partial_srt_list = translated_partial_srt_text.split('\n\n\n')
translated_lines_list += translated_partial_srt_list