From 039f878f7fab1e0f4efa8240458660e496293dc5 Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Mon, 28 Oct 2024 16:10:27 -0400 Subject: [PATCH] Bump argos-translate-files, fix src_lang initialization, checks --- libretranslate/app.py | 5 ++++- pyproject.toml | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/libretranslate/app.py b/libretranslate/app.py index cfedea8..705058f 100644 --- a/libretranslate/app.py +++ b/libretranslate/app.py @@ -855,7 +855,10 @@ def create_app(args): if source_lang == "auto": src_texts = argostranslatefiles.get_texts(filepath) candidate_langs = detect_languages(src_texts) - src_lang = candidate_langs[0] + detected_src_lang = candidate_langs[0] + src_lang = next(iter([l for l in languages if l.code == detected_src_lang["language"]]), None) + if src_lang is None: + abort(400, description=_("%(lang)s is not supported", lang=candidate_langs[0])) translated_file_path = argostranslatefiles.translate_file(src_lang.get_translation(tgt_lang), filepath) translated_filename = os.path.basename(translated_file_path) diff --git a/pyproject.toml b/pyproject.toml index 930e952..49709b5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,7 +48,7 @@ dependencies = [ "appdirs ==1.4.4", "APScheduler ==3.9.1", "translatehtml ==1.5.2", - "argos-translate-files ==1.1.4", + "argos-translate-files ==1.2.0", "itsdangerous ==2.1.2", "Werkzeug ==2.3.8", "requests ==2.31.0",