forked from i18next/i18next-gettext-converter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
program.js
executable file
·50 lines (39 loc) · 1.45 KB
/
program.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
#!/usr/bin/env node
var program = require('commander')
, converter = require("./lib/gettextWrapper")
, colors = require("colors");
// test calls:
// gettext -> i18next
// node program.js -l es -s ./testfiles/utf8.po
// node program.js -l es -s ./testfiles/utf8.po -t ./testfiles/translation.es.json
// i18next -> gettext
// node program.js -l de -s ./testfiles/de/source.de.json
// node program.js -l de -s ./testfiles/de/source.de.json -t ./testfiles/de/translation.de.po
// and back
// node program.js -l de -s ./testfiles/de/translation.de.po
// program
program
.version('0.0.1')
.option('-s, --source [path]', 'Specify path to read from')
.option('-t, --target [path]', 'Specify path to write to', '')
.option('-l, --language [domain]', 'Specify the language code, eg. \'en\'')
.option('-ks, --keyseparator [path]', 'Specify keyseparator you want to use, defaults to ##', '##')
.parse(process.argv);
if (program.source && program.language) {
console.log('\nstart converting'.yellow);
var options = {
keyseparator: program.keyseparator
};
converter.process(program.language, program.source, program.target, options, function(err) {
if (err) {
console.log('\nfailed writing file\n\n'.red);
} else {
console.log('\nfile written\n\n'.green);
}
});
} else {
console.log('\nat least call with argument -l and -t.'.red);
console.log('(call program with argument -h for help.)\n\n');
}
// expose to the world
module.exports = converter;