From 9831ba88a605ef5d197b0df4a86b950cec846631 Mon Sep 17 00:00:00 2001 From: dingedi Date: Mon, 30 May 2022 09:14:45 +0200 Subject: [PATCH] improve translation of punctuation --- app/app.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/app/app.py b/app/app.py index f3eccfc..935d7a0 100644 --- a/app/app.py +++ b/app/app.py @@ -475,6 +475,21 @@ def create_app(args): abort(400, description="%s format is not supported" % text_format) def improve_translation(source, translation): + source = source.strip() + + source_last_char = source[len(source) - 1] + translation_last_char = translation[len(translation) - 1] + + punctuation_chars = ['!', '?', '.', ',', ';'] + if source_last_char in punctuation_chars: + if translation_last_char != source_last_char: + if translation_last_char in punctuation_chars: + translation = translation[:-1] + + translation += source_last_char + elif translation_last_char in punctuation_chars: + translation = translation[:-1] + if source.islower(): return translation.lower()