-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathl10n.js
62 lines (55 loc) · 1.45 KB
/
l10n.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
/* eslint-disable no-console */
const cli = require('ember-cli');
const fs = require('fs');
const async = require('async');
/**
* Start an ember CLI command and return a promise
*
* @return Promise
*/
function runEmberCommand() {
const promise = cli({
cliArgs : [...arguments],
inputStream : process.stdin,
outputStream : process.stdout,
errorStream : process.stderr
});
promise.then(function() {
console.log('task completed');
}).catch(e => {
console.log('task failed');
console.error(e);
});
return promise;
}
const translationFiles = fs.readdirSync('translations').filter(fileName => fileName.endsWith('po'));
function extractStrings() {
return runEmberCommand('l10n:extract');
}
function mergeUpdatedTranslation() {
async.eachSeries(translationFiles, function(fileName, callback) {
runEmberCommand('l10n:extract', '-g', '-l', fileName.split('.')[0]).then(() => {
callback();
}).catch(console.error);
});
}
function generateTranslationJsonFiles() {
async.eachSeries(translationFiles, function(fileName, callback) {
runEmberCommand('l10n:convert', '-l', fileName.split('.')[0]).then(() => {
callback();
}).catch(console.error);
});
}
switch (process.argv[2]) {
case 'extract':
extractStrings();
break;
case 'update':
mergeUpdatedTranslation();
break;
case 'generate':
generateTranslationJsonFiles();
break;
default:
console.error('Invalid argument.');
}