From ab8bf6205c6dfae63ba8c2384aebbfbc73075e4f Mon Sep 17 00:00:00 2001 From: sienori Date: Thu, 15 Nov 2018 22:17:15 +0900 Subject: [PATCH] Display error message on translation panel --- simple-translate/simple-translate.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/simple-translate/simple-translate.js b/simple-translate/simple-translate.js index 3e36f33..303d0b2 100644 --- a/simple-translate/simple-translate.js +++ b/simple-translate/simple-translate.js @@ -113,18 +113,20 @@ button.addEventListener( ); async function translate(sourceWord, sourceLang, targetLang) { - const resultData = await T.translate(sourceWord, sourceLang, targetLang); - showResult(resultData.resultText, resultData.candidateText); + const result = await T.translate(sourceWord, sourceLang, targetLang); + showResult(result); panelPosition(clickPosition); } -function showResult(resultText, candidateText) { +function showResult(result) { panel.innerHTML = "

"; const resultArea = panel.getElementsByClassName("result")[0]; const candidateArea = panel.getElementsByClassName("candidate")[0]; - resultArea.innerText = resultText; - if (S.get().ifShowCandidate) candidateArea.innerText = candidateText; + resultArea.innerText = result.resultText; + if (S.get().ifShowCandidate) candidateArea.innerText = result.candidateText; + if (result.statusText == "Service Unavailable") + candidateArea.innerText = browser.i18n.getMessage("unavailableError"); } //パネル表示