-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
436 lines (364 loc) · 9.47 KB
/
index.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
<!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>
<body>
<style>
.center-div {
width: 1000px;
height:1000px;
}
.div {
width: 500px;
height: 450px;
color: black;
margin-left: 500px;
position: relative;
top:200px;
background: rgba(255,255,255,.05);
box-shadow: 0 0 10px rgba(0,0,0,0.25);
backdrop-filter: blur(20px);
border-radius: 8px;
}
.div:hover {
transform: scale(1.04) ;
}
body {
background-image: url("https://fiverr-res.cloudinary.com/images/t_main1,q_auto,f_auto,q_auto,f_auto/gigs/161591329/original/c2a3d15c165110e48a2321cae1483a92b6460822/project-or-individual-language-translator.jpg");
overflow: hidden;
background-repeat: no-repeat;
background-size: 115%;
}
#fname {
margin-top: 50px;
margin-left: 100px;
padding: 10px;
width: 300px;
border-radius: 5px;
border: 1px solid black;
-webkit-transition: all 0.30s ease-in-out;
outline: none;
}
#fname:focus , #sname:focus {
box-shadow: 0 0 5px rgba(81, 203, 238, 1);
border: 1px solid rgba(81, 203, 238, 1);
}
#sname {
margin-top: 40px;
margin-left: 70px;
padding: 10px;
width: 300px;
border-radius: 5px;
border: 1px solid black;
-webkit-transition: all 0.30s ease-in-out;
outline: none;
background-color: white;
color: black;
}
#lang1 {
margin-top: 5px;
margin-left: 100px;
padding: 10px;
width: 300px;
border-radius: 5px;
border: 1px solid black;
-webkit-transition: all 0.30s ease-in-out;
outline: none;
background-color: white;
color: black;
}
#lang2 {
margin-top: 15px;
margin-left: 100px;
padding: 10px;
width: 300px;
border-radius: 5px;
border: 1px solid black;
-webkit-transition: all 0.30s ease-in-out;
outline: none;
background-color: white;
color: black;
}
#submit {
margin-top: 40px;
margin-left: 200px;
padding: 10px;
width: 100px;
border-radius: 5px;
border: none;
background-color: dodgerblue;
color: white;
}
#copyBtn {
padding: 10px;
border-radius: 5px;
border: none;
position: relative;
bottom: 22px;
width: 70px;
height: 45px;
background-color: dodgerblue;
color: white;
}
#submit:hover {
transform: scale(1.02);
}
#percentage {
margin-top: 60px;
position: relative;
top:30px;
color:white;
margin-left: 180px;
font-family: sans-serif;
font-size: 18px;
font-weight: bold;
}
.start-h1 {
text-align: center;
position: relative;
top:40px;
color: white;
font-family: sans-serif;
font-size: 20px;
}
.trans-img {
width: 300px;
height: 850px;
position: absolute;
top:160px;
left: 100px;
}
.trans-img2 {
width: 350px;
height: 850px;
position: absolute;
top:170px;
right: 30px;
}
</style>
<div class="center-div">
</div>
<script>
let div;
div = document.createElement("div");
div.setAttribute("class","div");
div.innerHTML = `
<h1 class="start-h1">Language Translator</h1>
<textarea type="text" id="fname" placeholder="Enter the text to convert into Image"></textarea>
<input id="lang1" placeholder="Enter your text language"/>
<input id="lang2" placeholder="Enter To Convert Language"/>
<button id="submit">Submit</button>
<textarea id="sname" value="" disabled placeholder="Copy Your Translated Text here"></textarea>
<button id="copyBtn">Copy</button>
`;
document.querySelector(".center-div").append(div);
let button = document.getElementById("submit");
button.addEventListener("click",(event) => {
event.preventDefault();
let fname = document.getElementById("fname").value;
console.log(fname);
let lang1 = document.getElementById("lang1").value.toLowerCase();
console.log(lang1);
let lang2 = document.getElementById("lang2").value.toLowerCase();
console.log(lang2);
let languageObject = {
"Afrikaans": "af",
"Albanian": "sq",
"Amharic": "am",
"Arabic": "ar",
"Armenian": "hy",
"Assamese": "as",
"Aymara": "ay",
"Azerbaijani": "az",
"Bambara": "bm",
"Basque": "eu",
"Belarusian": "be",
"Bengali": "bn",
"Bhojpuri": "bho",
"Bosnian": "bs",
"Bulgarian": "bg",
"Catalan": "ca",
"Cebuano": "ceb",
"Chinese": "zh-CN or zh (BCP-47)",
"Chinese (Traditional)": "zh-TW (BCP-47)",
"Corsican": "co",
"Croatian": "hr",
"Czech": "cs",
"Danish": "da",
"Dhivehi": "dv",
"Dogri": "doi",
"Dutch": "nl",
"English": "en",
"Esperanto": "eo",
"Estonian": "et",
"Ewe": "ee",
"Filipino": "fil",
"Finnish": "fi",
"French": "fr",
"Frisian": "fy",
"Galician": "gl",
"Georgian": "ka",
"German": "de",
"Greek": "el",
"Guarani": "gn",
"Gujarati": "gu",
"Haitian Creole": "ht",
"Hausa": "ha",
"Hawaiian": "haw",
"Hebrew": "he or iw",
"Hindi": "hi",
"Hmong": "hmn",
"Hungarian": "hu",
"Icelandic": "is",
"Igbo": "ig",
"Ilocano": "ilo",
"Indonesian": "id",
"Irish": "ga",
"Italian": "it",
"Japanese": "ja",
"Javanese": "jv or jw",
"Kannada": "kn",
"Kazakh": "kk",
"Khmer": "km",
"Kinyarwanda": "rw",
"Konkani": "gom",
"Korean": "ko",
"Krio": "kri",
"Kurdish": "ku",
"Kurdish": "ckb",
"Kyrgyz": "ky",
"Lao": "lo",
"Latin": "la",
"Latvian": "lv",
"Lingala": "ln",
"Lithuanian": "lt",
"Luganda": "lg",
"Luxembourgish": "lb",
"Macedonian": "mk",
"Maithili": "mai",
"Malagasy": "mg",
"Malay": "ms",
"Malayalam": "ml",
"Maltese": "mt",
"Maori": "mi",
"Marathi": "mr",
"Meiteilon": "mni-Mtei",
"Mizo": "lus",
"Mongolian": "mn",
"Nepali": "ne",
"Norwegian": "no",
"Nyanja": "ny",
"Odia": "or",
"Oromo": "om",
"Pashto": "ps",
"Persian": "fa",
"Polish": "pl",
"Portuguese": "pt",
"Punjabi": "pa",
"Quechua": "qu",
"Romanian": "ro",
"Russian": "ru",
"Samoan": "sm",
"Sanskrit": "sa",
"Scots Gaelic": "gd",
"Sepedi": "nso",
"Serbian": "sr",
"Sesotho": "st",
"Shona": "sn",
"Sindhi": "sd",
"Sinhala": "si",
"Slovak": "sk",
"Slovenian": "sl",
"Somali": "so",
"Spanish": "es",
"Sundanese": "su",
"Swahili": "sw",
"Swedish": "sv",
"Tagalog": "tl",
"Tajik": "tg",
"Tamil": "ta",
"Tatar": "tt",
"Telugu": "te",
"Thai": "th",
"Tigrinya": "ti",
"Tsonga": "ts",
"Turkish": "tr",
"Turkmen": "tk",
"Twi": "ak",
"Ukrainian": "uk",
"Urdu": "ur",
"Uyghur": "ug",
"Uzbek": "uz",
"Vietnamese": "vi",
"Welsh": "cy",
"Xhosa": "xh",
"Yiddish": "yi",
"Yoruba": "yo",
"Zulu": "zu",
};
console.log(languageObject);
// Search for key that matches the input value
let findvalue = Object.keys(languageObject).find(function(key) {
return key.toLowerCase() === lang1;
});
let findvalue2 = Object.keys(languageObject).find(function(key) {
return key.toLowerCase() === lang2;
});
console.log(findvalue);
console.log(findvalue2);
const encodedParams = new URLSearchParams();
encodedParams.append("q", `${fname}`);
encodedParams.append("target", languageObject[findvalue2]);
encodedParams.append("source", languageObject[findvalue]);
const options = {
method: 'POST',
headers: {
'content-type': 'application/x-www-form-urlencoded',
'Accept-Encoding': 'application/gzip',
'X-RapidAPI-Key': '5209d67708msh2b4c4487ee24df4p1a9455jsn60b60f48436e',
'X-RapidAPI-Host': 'google-translate1.p.rapidapi.com'
},
body: encodedParams
};
let url = `https://google-translate1.p.rapidapi.com/language/translate/v2`;
let x;
fetch(url, options)
.then(response => response.json())
.then(response => {
console.log(response)
x = response.data.translations[0]["translatedText"];
console.log(x);
document.getElementById("sname").value = x;
document.getElementById("sname").style.backgroundColor = "whitesmoke";
})
.catch(err => console.error(err));
});
// Get the input element and copy button
let input = document.getElementById("sname");
let copyBtn = document.getElementById("copyBtn");
// Add click event listener to the copy button
copyBtn.addEventListener("click", function() {
// Select the text inside the input element
input.select();
input.setSelectionRange(0, 99999); // For mobile devices
// Copy the selected text to clipboard
document.execCommand("copy");
// Copy the selected text to clipboard
navigator.clipboard.writeText(input.value);
// Deselect the input element
input.blur();
input.style.backgroundColor = "grey";
// Update the copy button text
copyBtn.innerHTML = "Copied!";
});
// const option = {
// method : 'GET',
// let arr : PluginArray();
// };
</script>
</body>
</html>