-
Notifications
You must be signed in to change notification settings - Fork 12
/
index.js
62 lines (57 loc) · 1.85 KB
/
index.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
57
58
59
60
61
62
"use strict";
const Config = require('./parameters.json');
const Vorpal = require('vorpal')();
const Translate = require('@google-cloud/translate')({
key: Config.parameters.api_key
});
const Slugify = require("slugify");
const Clipboardy = require('clipboardy');
const Ora = require('ora');
const Spinner = new Ora({
text : Config.parameters.spinner_text,
color: Config.parameters.spinner_color
});
let Languages = Config.parameters.support_language;
Vorpal
.command('trino <text> <target>')
.validate(function(args) {
if (Languages.indexOf(args.target) === -1 || !args.text) {
Spinner.fail([`Incorrect parameters: <text> => ${args.text} <target> => ${args.target}`]);
return false;
} else {
return true;
}
})
.autocomplete(Languages)
.option('--c, --copy')
.option('--s, --slug')
.action(function(args, callback) {
Spinner.start();
Translate.translate(args.text, args.target)
.then((results) => {
const translation = results[0];
if (args.options.copy) {
Clipboardy.writeSync((args.options.slug ? Slugify(translation.toLowerCase()) : translation));
}
setTimeout(() => {
Spinner.succeed([`Translation: ${translation }`]);
}, 1000)
});
callback();
});
Vorpal
.command('trino-dt <text>')
.action(function(args, callback) {
Spinner.start();
Translate.detect(args.text)
.then((results) => {
let detections = results[0];
setTimeout(() => {
Spinner.succeed([`Detect: ${detections.language}`]);
}, 1000)
});
callback();
})
Vorpal
.delimiter('trino$:')
.show();