From 2b0074b94f46689b40a298c427105e325f7c979c Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Sat, 10 Dec 2022 00:21:38 -0500 Subject: [PATCH] Only show target languages, check swap, bump version --- VERSION | 2 +- app/app.py | 5 +++++ app/static/js/app.js | 16 +++++++++++++++- app/templates/index.html | 2 +- 4 files changed, 22 insertions(+), 3 deletions(-) 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 40d0095..9976ac0 100644 --- a/app/app.py +++ b/app/app.py @@ -272,6 +272,11 @@ def create_app(args): name: type: string description: Human-readable language name (in English) + targets: + type: array + items: + type: string + description: Supported target language codes """ return jsonify([{"code": l.code, "name": l.name, "targets": language_pairs.get(l.code, [])} for l in languages]) diff --git a/app/static/js/app.js b/app/static/js/app.js index d523359..d32b140 100644 --- a/app/static/js/app.js +++ b/app/static/js/app.js @@ -143,6 +143,14 @@ document.addEventListener('DOMContentLoaded', function(){ }, 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