-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
46 lines (32 loc) · 1.27 KB
/
app.js
File metadata and controls
46 lines (32 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
function loadLanguages(){
const langs = ["eng","pol","fra","deu","es","mk","ara","tr","pt","it"];
var options = null;
var from = document.getElementById('from');
var to = document.getElementById('to');
langs.forEach(l => {
options+= '<option>' + l + '</option>';
});
from.innerHTML = options;
to.innerHTML = options;
}
function translatePhrase(){
var from = document.getElementById('from').value;
var to = document.getElementById('to').value;
var phrase = document.getElementById('fromPhrase').value;
var url = "https://glosbe.com/gapi/translate?from=" + from + "&dest=" + to + "&format=json&phrase=" + phrase + "&pretty=true";
console.log(url);
console.log(phrase);
fetch(url)
.then(response => {
if(response.status !== 200){
console.error("API failed , Status code: " + response.status);
return;
}
response.json().then(data => {
document.getElementById("toPhrase").value = data.tuc[0].phrase ? data.tuc[0].phrase.text : "" ;
console.log(phrase);
});
}).catch(err => {
console.error("Fetch error "+ err);
});
}