From 90326051385aecb980f392dc85915d8f66df76e5 Mon Sep 17 00:00:00 2001 From: Seth Falco Date: Sat, 8 Jul 2023 11:58:26 +0100 Subject: [PATCH 1/3] fix: request and push notification on file translations --- libretranslate/templates/app.js.template | 25 ++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/libretranslate/templates/app.js.template b/libretranslate/templates/app.js.template index b788830..6f75305 100644 --- a/libretranslate/templates/app.js.template +++ b/libretranslate/templates/app.js.template @@ -25,7 +25,7 @@ document.addEventListener('DOMContentLoaded', function(){ translatedText: "", output: "", charactersLimit: -1, - + detectedLangText: "", copyTextLabel: {{ _e("Copy text") }}, @@ -212,7 +212,7 @@ document.addEventListener('DOMContentLoaded', function(){ this.timeout = null; this.detectedLangText = ""; - + if (this.inputText === ""){ this.translatedText = ""; this.output = ""; @@ -247,7 +247,7 @@ document.addEventListener('DOMContentLoaded', function(){ if (self.refreshOnce()) return; } {% endif %} - + var res = JSON.parse(this.response); // Success! if (res.translatedText !== undefined){ @@ -405,6 +405,7 @@ document.addEventListener('DOMContentLoaded', function(){ link.target = "_blank"; link.href = self.translatedFileUrl; link.click(); + handleNotification("Translation Complete", "Finished translating " + self.inputFile.name + "."); }else{ throw new Error(res.error || {{ _e("Unknown error") }}); } @@ -413,22 +414,27 @@ document.addEventListener('DOMContentLoaded', function(){ self.error = e.message; self.loadingFileTranslation = false; self.inputFile = false; + handleNotification("Translation Failed", e.message); } }else{ let res = JSON.parse(this.response); self.error = res.error || {{ _e("Unknown error") }}; self.loadingFileTranslation = false; self.inputFile = false; + handleNotification("Translation Failed", self.error); } } 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.inputFile = false; + handleNotification("Translation Failed", message); }; translateFileRequest.send(data); + Notification.requestPermission(); } } }); @@ -474,6 +480,17 @@ function handleLangsResponse(self, response) { self.loading = false; } +/** + * @param {string} title + * @param {string} body + */ +function handleNotification(title, body) { + new Notification(title, { + body, + tag: 'libretranslate' + }); +} + /** * @param {object} langDropdown * @param {string} lang From b3ac81ebcaaa3220e0c79d7e472815d68c86f14c Mon Sep 17 00:00:00 2001 From: Seth Falco Date: Sat, 8 Jul 2023 11:58:46 +0100 Subject: [PATCH 2/3] fix: avoid browser pop-up message --- libretranslate/templates/app.js.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libretranslate/templates/app.js.template b/libretranslate/templates/app.js.template index 6f75305..a48676d 100644 --- a/libretranslate/templates/app.js.template +++ b/libretranslate/templates/app.js.template @@ -402,8 +402,8 @@ document.addEventListener('DOMContentLoaded', function(){ self.translatedFileUrl = res.translatedFileUrl; let link = document.createElement("a"); - link.target = "_blank"; link.href = self.translatedFileUrl; + link.download = ""; link.click(); handleNotification("Translation Complete", "Finished translating " + self.inputFile.name + "."); }else{ From 193b6284d43314cb6980386c7631f58cc544bc25 Mon Sep 17 00:00:00 2001 From: Seth Falco Date: Sat, 8 Jul 2023 11:59:07 +0100 Subject: [PATCH 3/3] fix: fix error message UI on dark mode --- libretranslate/static/css/main.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libretranslate/static/css/main.css b/libretranslate/static/css/main.css index 862153a..1d5ac64 100644 --- a/libretranslate/static/css/main.css +++ b/libretranslate/static/css/main.css @@ -436,7 +436,7 @@ code[class*="language-"], pre[class*="language-"] { background-color: var(--pri-bg-color); } -.card-stacked { +.card-stacked, .card-stacked .card-content { background-color: var(--sec-bg-color) }