-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
54 lines (45 loc) · 1.31 KB
/
cli.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
#! /usr/bin/env node
'use strict';
var multiline = require( 'multiline' );
var translateResx = require( './translate-resx' );
var args = require( 'yargs' )
.usage( '$0 <cmd> [args]' )
.option( 'version', {
alias: 'v',
describe: 'Package Version'
} )
.option( 'file', {
alias: 'f',
describe: 'RESX File to Translate'
} )
.demand( 'f' )
.option( 'locale', {
alias: 'l',
describe: 'Locale to Translate to || Defaults to \'es\''
} )
.demand( 'l' )
// .option( 'key', {
// alias: 'k',
// describe: 'API Key for use with configure'
// } )
.command( 'ls', 'List available Google Translate locales', {}, function ( argv ) {
var locale = 'en';
translateResx.locales( locale );
} )
// .command( 'configure', 'set Google Translate API Key', {}, function ( argv ) {
// //echo('export TESTENV='+argv.key);
// } )
.example( '$0 -f foo.resx -l es', 'Translate foo.resx to foo.es.resx' )
.help( 'help' )
.alias( 'help', 'h' )
.argv;
if ( ( args.v ) || ( args.version ) ) {
console.log();
return console.log( require( './package' ).version );
}
if ( ( args.f ) || ( args.file ) && ( args.l ) || ( args.locale ) ) {
var locale = args.l || 'es';
var filepath = args.f || args.file;
locale = locale.toLowerCase();
translateResx.translate( filepath, locale );
}