From 2972292fc5f6f692911aa81c2b0245557bdd0486 Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Mon, 30 Oct 2023 13:09:39 -0400 Subject: [PATCH] Fix string index out of range fault --- libretranslate/app.py | 1 + libretranslate/language.py | 3 +++ 2 files changed, 4 insertions(+) diff --git a/libretranslate/app.py b/libretranslate/app.py index a5a77a8..c888861 100644 --- a/libretranslate/app.py +++ b/libretranslate/app.py @@ -644,6 +644,7 @@ def create_app(args): } ) except Exception as e: + raise e abort(500, description=_("Cannot translate text: %(text)s", text=str(e))) @bp.post("/translate_file") diff --git a/libretranslate/language.py b/libretranslate/language.py index 86921bc..44f926f 100644 --- a/libretranslate/language.py +++ b/libretranslate/language.py @@ -107,6 +107,9 @@ def improve_translation_formatting(source, translation, improve_punctuation=True if source.isupper(): return translation.upper() + if len(translation) == 0: + return source + if source[0].islower(): return translation[0].lower() + translation[1:]