-
Notifications
You must be signed in to change notification settings - Fork 0
/
translate.html
88 lines (70 loc) · 1.91 KB
/
translate.html
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<style>
#container {
display: flex;
/* border: 1px solid; */
margin:auto;
width:80%
}
#input-section {
flex: 1;
}
#output-section {
flex: 1;
border: 1px solid ;
height: 200px;
}
</style>
<body>
<div id="container">
<div id="input-section">
<!--Create button that will run translate text function, give id "translate-btn"-->
<button onclick="translateor()" id="translate-btn">Tanslate</button>
<!--Create input that will accept text to be translated, give id "input-text"-->
<div>
<textarea name="" id="input-text" cols="30" rows="10"></textarea>
</div>
</div>
<div id="output-section">
<p id="translated-text">
<!--Show translated text here-->
</p>
</div>
</div>
</body>
</html>
<script>
async function translateor(){
try{
let input= document.getElementById("input-text").value
let res= await fetch(`https://libretranslate.de/translate`,{
method:"POST",
body:JSON.stringify({
q:input,
source:"en",
target:"odia",
format:"text",
}),
headers:{ // headers=metadata
"Content-Type": "application/json"
},
});
let data= await res.json()
console.log("data:",data)
showtranslatedata(data)
}
catch(err){
console.log(err)
}
}
function showtranslatedata(data){
let translated_text= document.getElementById("translated-text").innerText=data.translatedText
}
</script>