-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
34 lines (27 loc) · 809 Bytes
/
main.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
var translate = require('translate-api');
var fs = require('fs');
var path = require('path');
function text2fr(transText) {
return translate.getText(transText, { from: 'en', to: 'fr' });
}
var frJson = fs.readFileSync(path.resolve(__dirname, 'fr.json'), 'utf8');
var words = JSON.parse(frJson);
var messages = {};
var job = Object.keys(words).reduce((job, key) => {
var word = words[key];
return job.then(_ => {
console.log('Translating ', word);
return text2fr(word).then(translation => {
messages[key] = translation.text;
console.log('Got ', translation.text);
return translation;
});
});
}, Promise.resolve());
job.then(_ => {
fs.writeFileSync(
path.resolve(__dirname, 'en.json'),
JSON.stringify(messages, null, 2),
);
console.log('Succès');
});