-
Notifications
You must be signed in to change notification settings - Fork 0
/
translateor.html
140 lines (129 loc) · 3.73 KB
/
translateor.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<!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>
#overview {
width: 90%;
margin: auto;
display: flex;
justify-content: space-between;
border: 1px solid black;
background-image: url(https://www.docusign.com/sites/default/files/styles/hero_standard__2x_mobile/public/convert-word-document-fillable-form.jpg?itok=FIFWVj0d×tamp=1605051701);
}
#overview > div {
margin: 3%;
height: 300px;
width: 48%;
border: 1px solid black;
background-color: aliceblue;
/* background-image: url(https://www.docusign.com/sites/default/files/styles/hero_standard__2x_mobile/public/convert-word-document-fillable-form.jpg?itok=FIFWVj0d×tamp=1605051701); */
}
#inputText {
width: 90%;
margin-left: 2em;
height: 220px;
}
#output_value {
width: 90%;
margin-left: 1.5em;
border: 1px solid black;
height: 220px;
}
.box {
display: flex;
justify-content: center;
align-items: center;
}
.box #inp_lang,
#out_lang {
width: 40%;
height: 30px;
margin: 2%;
}
#voice {
/* border: 1px solid black; */
margin-top: -1rem;
}
#voice :hover {
cursor: pointer;
}
</style>
<body>
<div id="overview">
<div id="input">
<div class="box">
<select id="inp_lang">
<option value="en">English</option>
<option value="hi">Hindi</option>
</select>
</div>
<!-- <button type="button" onclick="trasnlate()">button</button> -->
<textarea
name="input_value"
placeholder="Enter Text ..."
id="inputText"
oninput="trasnlate()"
></textarea>
<div>
<svg id="voice" width="1.5em" height="2em" viewBox="0 0 24 30">
<path
fill="currentColor"
d="M12 15c1.66 0 2.99-1.34 2.99-3L15 6c0-1.66-1.34-3-3-3S9 4.34 9 6v6c0 1.66 1.34 3 3 3zm5.3-3c0 3-2.54 5.1-5.3 5.1S6.7 15 6.7 12H5c0 3.42 2.72 6.23 6 6.72V22h2v-3.28c3.28-.48 6-3.3 6-6.72h-1.7z"
/>
</svg>
</div>
</div>
<div id="output">
<div class="box">
<select id="out_lang">
<option value="hi">Hindi</option>
<option value="en">English</option>
</select>
</div>
<div id="output_value"></div>
</div>
</div>
</body>
</html>
<script>
//helper function to get input value
function read(id) {
return document.querySelector(id).value;
}
let trasnlate = async () => {
try {
let input = read("#inputText");
let input_lang = read("#inp_lang");
let output_lang = read("#out_lang");
const res = await fetch(`https://libretranslate.de/translate`, {
method: "POST",
body: JSON.stringify({
q: input,
source: input_lang,
target: output_lang,
format: "text",
}),
//additional information about the request that server might need too know
headers: {
"Content-Type": "application/json",
},
});
const data = await res.json();
showTooutput(data);
console.log(data);
// document.querySelector("#output").innerHTML = data.translatedText;
} catch (error) {
console.log("yes",error);
input.innerHTML="love"
}
};
//properties inside data
let showTooutput = ({ translatedText }) => {
document.querySelector("#output_value").innerHTML = translatedText;
};
</script>