1
0
mirror of https://github.com/LibreTranslate/LibreTranslate.git synced 2024-12-24 10:06:43 +02:00
This commit is contained in:
Sébastien Thuret 2021-10-08 19:02:30 +02:00
parent 0214d7bfd6
commit f5bc2bc3f5
No known key found for this signature in database
GPG Key ID: 4742E2D66933BB08
2 changed files with 50 additions and 20 deletions

View File

@ -124,6 +124,13 @@ h3.header {
cursor: pointer;
}
.btn-blue {
color: #42A5F5;
}
.btn-action:disabled {
color: #777;
}
.btn-action span {
padding-right: 0.5rem;
}

View File

@ -148,16 +148,18 @@
<label for="textarea2" class="sr-only">
Translated text
</label>
<textarea id="textarea2" v-model="translatedText" ref="translatedTextarea" dir="auto" readonly></textarea>
<textarea id="textarea2" v-model="translatedText" ref="translatedTextarea" dir="auto" v-bind:readonly="!isSuggesting"></textarea>
<div class="actions">
<button v-if="inputText.length && !isSuggesting" class="btn-action" @click="suggestTranslation">
<i class="material-icons">edit</i>
</button>
<button v-if="inputText.length && isSuggesting" class="btn-action" @click="closeSuggestTranslation">
<i class="material-icons">close</i>
<button v-if="inputText.length && isSuggesting" class="btn-action btn-blue" @click="closeSuggestTranslation">
<span>Cancel</span>
</button>
<button class="btn-action btn-copy-translated" @click="copyText">
<button v-if="inputText.length && isSuggesting" :disabled="!canSendSuggestion" class="btn-action btn-blue" @click="sendSuggestion">
<span>Send</span>
</button>
<button v-if="!isSuggesting" class="btn-action btn-copy-translated" @click="copyText">
<span>[[ copyTextLabel ]]</span> <i class="material-icons">content_copy</i>
</button>
</div>
@ -388,8 +390,11 @@
isHtml: function(){
return htmlRegex.test(this.inputText);
}
},
},
canSendSuggestion() {
return this.translatedText.trim() !== "" && this.translatedText !== this.inputText;
}
},
filters: {
escape: function(v){
return v.replace('"', '\\\"');
@ -405,7 +410,9 @@
this.transRequest = null;
}
},
swapLangs: function(){
swapLangs: function(e){
this.closeSuggestTranslation(e)
var t = this.sourceLang;
this.sourceLang = this.targetLang;
this.targetLang = t;
@ -417,6 +424,8 @@
this.error = '';
},
handleInput: function(e){
this.closeSuggestTranslation(e)
if (this.timeout) clearTimeout(this.timeout);
this.timeout = null;
@ -494,6 +503,20 @@
e.preventDefault();
this.isSuggesting = false;
},
sendSuggestion: function(e) {
e.preventDefault();
var request = new XMLHttpRequest();
self.transRequest = request;
var data = new FormData();
data.append("q", self.inputText);
data.append("s", self.inputText);
data.append("source", self.sourceLang);
data.append("target", self.targetLang);
request.open('POST', BaseUrl + '/translate', true);
},
deleteText: function(e){
e.preventDefault();