mirror of
https://github.com/LibreTranslate/LibreTranslate.git
synced 2024-11-25 01:11:00 +00:00
fix: request and push notification on file translations
This commit is contained in:
parent
9052265d5b
commit
9032605138
1 changed files with 21 additions and 4 deletions
|
@ -25,7 +25,7 @@ document.addEventListener('DOMContentLoaded', function(){
|
||||||
translatedText: "",
|
translatedText: "",
|
||||||
output: "",
|
output: "",
|
||||||
charactersLimit: -1,
|
charactersLimit: -1,
|
||||||
|
|
||||||
detectedLangText: "",
|
detectedLangText: "",
|
||||||
|
|
||||||
copyTextLabel: {{ _e("Copy text") }},
|
copyTextLabel: {{ _e("Copy text") }},
|
||||||
|
@ -212,7 +212,7 @@ document.addEventListener('DOMContentLoaded', function(){
|
||||||
this.timeout = null;
|
this.timeout = null;
|
||||||
|
|
||||||
this.detectedLangText = "";
|
this.detectedLangText = "";
|
||||||
|
|
||||||
if (this.inputText === ""){
|
if (this.inputText === ""){
|
||||||
this.translatedText = "";
|
this.translatedText = "";
|
||||||
this.output = "";
|
this.output = "";
|
||||||
|
@ -247,7 +247,7 @@ document.addEventListener('DOMContentLoaded', function(){
|
||||||
if (self.refreshOnce()) return;
|
if (self.refreshOnce()) return;
|
||||||
}
|
}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
var res = JSON.parse(this.response);
|
var res = JSON.parse(this.response);
|
||||||
// Success!
|
// Success!
|
||||||
if (res.translatedText !== undefined){
|
if (res.translatedText !== undefined){
|
||||||
|
@ -405,6 +405,7 @@ document.addEventListener('DOMContentLoaded', function(){
|
||||||
link.target = "_blank";
|
link.target = "_blank";
|
||||||
link.href = self.translatedFileUrl;
|
link.href = self.translatedFileUrl;
|
||||||
link.click();
|
link.click();
|
||||||
|
handleNotification("Translation Complete", "Finished translating " + self.inputFile.name + ".");
|
||||||
}else{
|
}else{
|
||||||
throw new Error(res.error || {{ _e("Unknown error") }});
|
throw new Error(res.error || {{ _e("Unknown error") }});
|
||||||
}
|
}
|
||||||
|
@ -413,22 +414,27 @@ document.addEventListener('DOMContentLoaded', function(){
|
||||||
self.error = e.message;
|
self.error = e.message;
|
||||||
self.loadingFileTranslation = false;
|
self.loadingFileTranslation = false;
|
||||||
self.inputFile = false;
|
self.inputFile = false;
|
||||||
|
handleNotification("Translation Failed", e.message);
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
let res = JSON.parse(this.response);
|
let res = JSON.parse(this.response);
|
||||||
self.error = res.error || {{ _e("Unknown error") }};
|
self.error = res.error || {{ _e("Unknown error") }};
|
||||||
self.loadingFileTranslation = false;
|
self.loadingFileTranslation = false;
|
||||||
self.inputFile = false;
|
self.inputFile = false;
|
||||||
|
handleNotification("Translation Failed", self.error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
translateFileRequest.onerror = function() {
|
translateFileRequest.onerror = function() {
|
||||||
self.error = {{ _e("Cannot load %(url)s", url="/translate_file") }};
|
const message = {{ _e("Cannot load %(url)s", url="/translate_file") }};
|
||||||
|
self.error = message;
|
||||||
self.loadingFileTranslation = false;
|
self.loadingFileTranslation = false;
|
||||||
self.inputFile = false;
|
self.inputFile = false;
|
||||||
|
handleNotification("Translation Failed", message);
|
||||||
};
|
};
|
||||||
|
|
||||||
translateFileRequest.send(data);
|
translateFileRequest.send(data);
|
||||||
|
Notification.requestPermission();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -474,6 +480,17 @@ function handleLangsResponse(self, response) {
|
||||||
self.loading = false;
|
self.loading = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} title
|
||||||
|
* @param {string} body
|
||||||
|
*/
|
||||||
|
function handleNotification(title, body) {
|
||||||
|
new Notification(title, {
|
||||||
|
body,
|
||||||
|
tag: 'libretranslate'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {object} langDropdown
|
* @param {object} langDropdown
|
||||||
* @param {string} lang
|
* @param {string} lang
|
||||||
|
|
Loading…
Reference in a new issue