-
Notifications
You must be signed in to change notification settings - Fork 0
/
caps.js
40 lines (35 loc) · 814 Bytes
/
caps.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
const dotenv = require('dotenv').config();
const {google} = require('googleapis');
const Translates = google.translate({
version: 'v2',
auth: process.env.GOOGLE_API_KEY
})
if(process.argv.length < 5)
{
exit_usage();
}else
{
process.argv.forEach((value, index) => {
if(value == "")
{
exit_usage();
}
});
}
const og_text = process.argv[2];
const source = process.argv[3];
const target = process.argv[4];
Translates.translations.list({
source: source,
q: og_text,
target: target
}).then((res) => {
console.log(res.data.data.translations[0].translatedText);
}).catch((error) => {
console.log(error.response.data.error.message);
});
function exit_usage()
{
console.log('Usage : <string> <source> <target>');
process.exit(333);
}