silverstripe-webpack/app/transifex.js
2022-05-03 22:00:53 +02:00

34 lines
1.0 KiB
JavaScript

/**
* 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!
*/
const fs = require('fs')
const 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) {
const lang = file.split('.').shift()
fs.readFile(PATHS.SRC + '/' + file, 'utf8', function (err, data) {
if (err) { console.log(err) }
const 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')
})
})
})
})