Only show target languages, check swap, bump version

This commit is contained in:
Piero Toffanin 2022-12-10 00:21:38 -05:00
parent 0875fdc433
commit 2b0074b94f
4 changed files with 22 additions and 3 deletions

View file

@ -1 +1 @@
1.3.2 1.3.3

View file

@ -272,6 +272,11 @@ def create_app(args):
name: name:
type: string type: string
description: Human-readable language name (in English) 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]) return jsonify([{"code": l.code, "name": l.name, "targets": language_pairs.get(l.code, [])} for l in languages])

View file

@ -143,6 +143,14 @@ document.addEventListener('DOMContentLoaded', function(){
}, },
canSendSuggestion: function(){ canSendSuggestion: function(){
return this.translatedText.trim() !== "" && this.translatedText !== this.savedTanslatedText; 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: { filters: {
@ -161,7 +169,13 @@ document.addEventListener('DOMContentLoaded', function(){
} }
}, },
swapLangs: function(e){ 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; var t = this.sourceLang;
this.sourceLang = this.targetLang; this.sourceLang = this.targetLang;

View file

@ -156,7 +156,7 @@
</a> </a>
<span>Translate into</span> <span>Translate into</span>
<select class="browser-default" v-model="targetLang" ref="targetLangDropdown" @change="handleInput"> <select class="browser-default" v-model="targetLang" ref="targetLangDropdown" @change="handleInput">
<template v-for="option in langs"> <template v-for="option in targetLangs">
<option v-if="option.code !== 'auto'" :value="option.code">[[ option.name ]]</option> <option v-if="option.code !== 'auto'" :value="option.code">[[ option.name ]]</option>
</template> </template>
</select> </select>