initial commit
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
const translateHandler = async () => {
|
||||
|
||||
const textArea = document.getElementById("text-input");
|
||||
const localeArea = document.getElementById("locale-select");
|
||||
const errorArea = document.getElementById("error-msg");
|
||||
const translatedArea = document.getElementById("translated-sentence");
|
||||
|
||||
const stuff = { "text": textArea.value, "locale": localeArea.value };
|
||||
|
||||
errorArea.innerText = "";
|
||||
translatedArea.innerText = "";
|
||||
|
||||
const data = await fetch("/api/translate", {
|
||||
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Accept": "application/json",
|
||||
"Content-type": "application/json"
|
||||
},
|
||||
body: JSON.stringify(stuff)
|
||||
|
||||
});
|
||||
|
||||
const parsed = await data.json();
|
||||
|
||||
if (parsed.error) {
|
||||
|
||||
return errorArea.innerText = JSON.stringify(parsed);
|
||||
}
|
||||
|
||||
return translatedArea.innerHTML = parsed.translation;
|
||||
|
||||
};
|
||||
|
||||
document.getElementById("translate-btn").addEventListener("click", translateHandler)
|
||||
Reference in New Issue
Block a user