From 0478d4ee2cf66f7400a00456dafe946a4690b075 Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Fri, 9 Dec 2022 14:35:39 -0500 Subject: [PATCH] Handle empty translation --- app/app.py | 4 ++-- app/language.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/app.py b/app/app.py index fc13958..a25477b 100644 --- a/app/app.py +++ b/app/app.py @@ -501,9 +501,9 @@ def create_app(args): ) else: return jsonify( - { + { "translatedText": results - } + } ) else: translator = src_langs[0].get_translation(tgt_lang) diff --git a/app/language.py b/app/language.py index a19ad2f..3850722 100644 --- a/app/language.py +++ b/app/language.py @@ -81,9 +81,9 @@ def detect_languages(text): def improve_translation_formatting(source, translation, improve_punctuation=True): source = source.strip() - if not len(source): + if not len(source) or not len(translation): return "" - + if improve_punctuation: source_last_char = source[len(source) - 1] translation_last_char = translation[len(translation) - 1]