-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathpoeditor-push.js
More file actions
67 lines (59 loc) · 1.82 KB
/
poeditor-push.js
File metadata and controls
67 lines (59 loc) · 1.82 KB
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
63
64
65
66
67
var program = require('commander'),
CLI = require('clui'),
configure = require('./configure'),
api = require('./api'),
clc = require('cli-color'),
POEditorStaging = require('./staging');
program.version("1.0.0")
.description("Upload newly added/staged translations to POEditor");
configure(program).then(function(config){
var poeditorStaging = new POEditorStaging();
var stagingData = poeditorStaging.getStagingData();
var termData = [];
var langData = [];
Object.keys(stagingData).forEach(term => {
if (stagingData.hasOwnProperty(term)) {
var entry = stagingData[term];
termData.push({
term: entry.term,
context: entry.context,
tags: entry.tags,
reference: '',
plural: '',
comment: ''
});
langData.push({
term: {
term: entry.term,
context: entry.context
},
definition: {
forms: [entry.defaultTranslation],
fuzzy: 0
}
});
}
});
var spinner = new CLI.Spinner('Please wait, pushing ' + termData.length + ' terms to POEditor.');
spinner.start();
api.apiRequest(config.apiToken, 'add_terms', {
data: JSON.stringify(termData),
id: config.projectId
}).then(function(res) {
api.apiRequest(config.apiToken, 'update_language', {
language: config.defaultLanguage,
data: JSON.stringify(langData),
id: config.projectId
}).then(function(res) {
var response = res[0], details = res[1];
spinner.stop();
console.log("[ " + clc.green("OK") + " ] " + details.parsed + " terms were parsed, " + details.added + " terms were added and " + details.updated + " term updated.");
poeditorStaging.clearStaging();
}, function(){
console.log("[ " + clc.red("FAIL") + " ] Could not push terms to POEditor.");
});
}, function(){
spinner.stop();
console.log("[ " + clc.red("FAIL") + " ] Could not push terms to POEditor.");
});
});