diff --git a/VERSION b/VERSION index 1892b92..31e5c84 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.3.2 +1.3.3 diff --git a/app/app.py b/app/app.py index 36e1ad3..9976ac0 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] = sorted([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,13 @@ 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 + targets: + type: array + items: + type: string + description: Supported target language codes """ - 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 @@ -486,6 +485,9 @@ def create_app(args): results = [] for idx, text in enumerate(q): translator = src_langs[idx].get_translation(tgt_lang) + if translator is None: + abort(400, description="%s (%s) is not available as a target language from %s (%s)" % (tgt_lang.name, tgt_lang.code, src_langs[idx].name, src_langs[idx].code)) + if text_format == "html": translated_text = str(translate_html(translator, text)) else: @@ -501,12 +503,14 @@ def create_app(args): ) else: return jsonify( - { + { "translatedText": results - } + } ) else: translator = src_langs[0].get_translation(tgt_lang) + if translator is None: + abort(400, description="%s (%s) is not available as a target language from %s (%s)" % (tgt_lang.name, tgt_lang.code, src_langs[0].name, src_langs[0].code)) if text_format == "html": translated_text = str(translate_html(translator, q)) @@ -517,7 +521,7 @@ def create_app(args): return jsonify( { "translatedText": unescape(translated_text), - "detectedLanguage": source_langs[0] + "detectedLanguage": source_langs[0] } ) else: @@ -940,7 +944,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 a19ad2f..2e358c2 100644 --- a/app/language.py +++ b/app/language.py @@ -83,7 +83,10 @@ def improve_translation_formatting(source, translation, improve_punctuation=True 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/css/main.css b/app/static/css/main.css index 9a0ce4b..7ee8554 100644 --- a/app/static/css/main.css +++ b/app/static/css/main.css @@ -61,14 +61,6 @@ h3.header { position: relative; } -@-moz-document url-prefix() { - .language-select select { - -moz-appearance: none; - text-indent: -2px; - margin-right: -8px; - } -} - .language-select:after { content: ""; width: 0.5em; diff --git a/app/static/js/app.js b/app/static/js/app.js index cd53e0e..d32b140 100644 --- a/app/static/js/app.js +++ b/app/static/js/app.js @@ -141,8 +141,16 @@ document.addEventListener('DOMContentLoaded', function(){ isHtml: function(){ return htmlRegex.test(this.inputText); }, - canSendSuggestion() { + canSendSuggestion: function(){ return this.translatedText.trim() !== "" && this.translatedText !== this.savedTanslatedText; + }, + targetLangs: function(){ + if (!this.sourceLang) return this.langs; + else{ + var lang = this.langs.find(l => l.code === this.sourceLang); + if (!lang) return this.langs; + return lang.targets.map(t => this.langs.find(l => l.code === t)); + } } }, filters: { @@ -161,7 +169,13 @@ document.addEventListener('DOMContentLoaded', function(){ } }, swapLangs: function(e){ - this.closeSuggestTranslation(e) + this.closeSuggestTranslation(e); + + // Make sure that we can swap + // by checking that the current target language + // has source language as target + var tgtLang = this.langs.find(l => l.code === this.targetLang); + if (tgtLang.targets.indexOf(this.sourceLang) === -1) return; // Not supported var t = this.sourceLang; this.sourceLang = this.targetLang; diff --git a/app/templates/index.html b/app/templates/index.html index e9068ea..396754f 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -156,7 +156,7 @@ Translate into