-
Notifications
You must be signed in to change notification settings - Fork 0
/
transifex.js
34 lines (30 loc) · 1.06 KB
/
transifex.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
/**
* Parse all source JS language files (JSON pulled from Transifex) from client/src/lang
* to SilverStripe i18n js file in client/lang
* Quick and dirty node script!
*/
var fs = require('fs');
var path = require('path');
const PATHS = {
SRC: path.resolve('client/src/lang'),
DIST: path.resolve('client/lang'),
};
console.log('Writing SS i18n JS lang files...');
fs.readdir(PATHS.SRC, function(err, files)
{
files.forEach(function (file) {
var lang = file.split('.').shift();
fs.readFile(PATHS.SRC + '/' + file, "utf8", function(err, data) {
if (err) { console.log(err); }
var fileData = `if(typeof(ss) == 'undefined' || typeof(ss.i18n) == 'undefined') {
if(typeof(console) != 'undefined') console.error('Class ss.i18n not defined');
} else {
ss.i18n.addDictionary('${lang}', ${data});
}`;
fs.writeFile(PATHS.DIST + '/' + lang + '.js', fileData, "utf8", function(err) {
if (err) { console.log(err); }
console.log("Saved " + lang + '.js');
});
});
});
});