From e79089b5c15d1c0ca499b22637d7baea58e3bca2 Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Fri, 9 Dec 2022 16:36:12 -0500 Subject: [PATCH] Extend /languages to include targets --- app/app.py | 16 +++++----------- app/language.py | 5 ++++- app/static/js/app.js | 2 +- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/app/app.py b/app/app.py index a25477b..70b5677 100644 --- a/app/app.py +++ b/app/app.py @@ -112,6 +112,9 @@ def create_app(args): if not args.disable_files_translation: remove_translated_files.setup(get_upload_dir()) languages = load_languages() + language_pairs = {} + for lang in languages: + language_pairs[lang.code] = [l.to_lang.code for l in lang.translations_from] # Map userdefined frontend languages to argos language object. if args.frontend_language_source == "auto": @@ -269,17 +272,8 @@ def create_app(args): name: type: string description: Human-readable language name (in English) - 429: - description: Slow down - schema: - id: error-slow-down - type: object - properties: - error: - type: string - description: Reason for slow down """ - return jsonify([{"code": l.code, "name": l.name} for l in languages]) + return jsonify([{"code": l.code, "name": l.name, "targets": [language_pairs.get(l.code, [])]} for l in languages]) # Add cors @app.after_request @@ -940,7 +934,7 @@ def create_app(args): return jsonify({"success": True}) swag = swagger(app) - swag["info"]["version"] = "1.3.0" + swag["info"]["version"] = "1.3.1" swag["info"]["title"] = "LibreTranslate" @app.route("/spec") diff --git a/app/language.py b/app/language.py index 3850722..2e358c2 100644 --- a/app/language.py +++ b/app/language.py @@ -81,9 +81,12 @@ def detect_languages(text): def improve_translation_formatting(source, translation, improve_punctuation=True): source = source.strip() - if not len(source) or not len(translation): + if not len(source): return "" + if not len(translation): + return source + if improve_punctuation: source_last_char = source[len(source) - 1] translation_last_char = translation[len(translation) - 1] diff --git a/app/static/js/app.js b/app/static/js/app.js index cd53e0e..d523359 100644 --- a/app/static/js/app.js +++ b/app/static/js/app.js @@ -141,7 +141,7 @@ document.addEventListener('DOMContentLoaded', function(){ isHtml: function(){ return htmlRegex.test(this.inputText); }, - canSendSuggestion() { + canSendSuggestion: function(){ return this.translatedText.trim() !== "" && this.translatedText !== this.savedTanslatedText; } },