-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
21 lines (18 loc) · 866 Bytes
/
Copy pathscript.js
File metadata and controls
21 lines (18 loc) · 866 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
const textoInput = document.getElementById('texto');
const idiomaOrigemSelect = document.getElementById('idiomaOrigem');
const idiomaDestinoSelect = document.getElementById('idiomaDestino');
const traduzirButton = document.getElementById('traduzir');
const resultadoDiv = document.getElementById('resultado');
traduzirButton.addEventListener('click', () => {
const texto = textoInput.value;
const idiomaOrigem = idiomaOrigemSelect.value;
const idiomaDestino = idiomaDestinoSelect.value;
const url = `https://translate.googleapis.com/translate_a/single?client=gtx&sl=${idiomaOrigem}&tl=${idiomaDestino}&dt=t&q=${encodeURI(texto)}`;
fetch(url)
.then(response => response.json())
.then(data => {
const traducao = data[0][0][0];
resultadoDiv.innerText = traducao;
})
.catch(error => console.error(error));
});