-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·37 lines (36 loc) · 942 Bytes
/
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
#!/bin/env node
var fs = require('mz/fs'),
options = { from: 'ja', to: 'en' },
http = require('http'),
https = require('https'),
url = require('url'),
getExt = require('./get-external'),
translate = require('./translate')
if (process.argv.length > 2)
process.argv.slice(2).forEach(dosub)
else translate()
function dosub(file, i) {
try {
if (/^{.*}$/i.test(file))
return options = Object.assign({},
options,
JSON.parse(file)
)
else if (/\.json$/i.test(file))
return options = Object.assign({},
options,
require(file)
)
else if (/^https:/i.test(file))
return https.get(file, getExt(options, file, i))
else if (/^http:/i.test(file))
return http.get(file, getExt(options, file, i))
else return fs.readFile(file, 'utf8')
.then()
.then(text => translate(Object.assign({},
options,
{ text, it: i, filename: file }
)))
.catch(console.error)
} catch (e) {}
}