-
Notifications
You must be signed in to change notification settings - Fork 1
/
translate.js
56 lines (48 loc) · 1.28 KB
/
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
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
const axios = require("axios");
module.exports = async function (fromLang, toLang, msg, verbose = false) {
if (verbose) {
console.log("translate -- Translate: " + msg);
console.log("translate -- From: " + fromLang);
console.log("translate -- To: " + toLang);
}
let postReq = await axios({
method: "post",
url: "https://api-free.deepl.com/v2/translate",
params: {
auth_key: process.env.DEEPLKEY,
source_lang: fromLang,
target_lang: toLang,
text: msg,
},
});
var resp = {
from: fromLang,
to: toLang,
msg: msg,
transMsg: postReq.data.translations[0].text,
};
// console.log(resp);
// var transMsg = postReq.data.translations[0].text;
// console.log(transMsg);
// postReq.then(function (response) {
// // console.log("translate -- " + response.data);
// // console.log(typeof response.data);
// var transMsg = response.data.translations[0].text;
// // console.log("translate -- " + transMsg);
// var resp = {
// from: fromLang,
// to: toLang,
// msg: msg,
// transMsg: transMsg,
// };
// });
// create response
// // create response
// var resp = {
// from: fromLang,
// to: toLang,
// msg: msg,
// transMsg: "fast reply",
// };
return resp;
};