2018-04-21 05:36:06 +02:00
|
|
|
/**
|
|
|
|
* 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!
|
|
|
|
*/
|
2022-05-03 22:00:53 +02:00
|
|
|
const fs = require('fs')
|
|
|
|
const path = require('path')
|
2018-04-21 05:36:06 +02:00
|
|
|
|
|
|
|
const PATHS = {
|
|
|
|
SRC: path.resolve('client/src/lang'),
|
2022-05-03 22:00:53 +02:00
|
|
|
DIST: path.resolve('client/lang')
|
|
|
|
}
|
2018-04-21 05:36:06 +02:00
|
|
|
|
2022-05-03 22:00:53 +02:00
|
|
|
console.log('Writing SS i18n JS lang files...')
|
2018-04-21 05:36:06 +02:00
|
|
|
|
2022-05-03 22:00:53 +02:00
|
|
|
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') {
|
2018-04-21 05:36:06 +02:00
|
|
|
if(typeof(console) != 'undefined') console.error('Class ss.i18n not defined');
|
|
|
|
} else {
|
|
|
|
ss.i18n.addDictionary('${lang}', ${data});
|
2022-05-03 22:00:53 +02:00
|
|
|
}`
|
2018-04-21 05:36:06 +02:00
|
|
|
|
2022-05-03 22:00:53 +02:00
|
|
|
fs.writeFile(PATHS.DIST + '/' + lang + '.js', fileData, 'utf8', function (err) {
|
|
|
|
if (err) { console.log(err) }
|
|
|
|
console.log('Saved ' + lang + '.js')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|