-
Notifications
You must be signed in to change notification settings - Fork 0
/
translate.js
29 lines (25 loc) · 862 Bytes
/
translate.js
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
async function main() {
const url = 'https://text-translator2.p.rapidapi.com/translate';
const input = document.getElementById("translate").value
const options = {
method: 'POST',
headers: {
'content-type': 'application/x-www-form-urlencoded',
'X-RapidAPI-Key': '5f123922cdmsh8fe8d5753678f6dp1970aejsn7b1720d122cd',
'X-RapidAPI-Host': 'text-translator2.p.rapidapi.com'
},
body: new URLSearchParams({
source_language: 'en',
target_language: 'fr',
text: input,
})
};
console.log(input);
try {
const response = await fetch(url, options);
const result = await response.json();
document.getElementById("outtext").innerText = result.data.translatedText;
} catch (error) {
console.error(error);
}
}