i18n: .po compilation

This commit is contained in:
Bat 2018-04-08 17:38:26 +01:00
commit e7b06ab509
6 changed files with 60 additions and 0 deletions

31
front/build/i18n.js Normal file
View file

@ -0,0 +1,31 @@
const fs = require('fs');
const path = require('path');
const { gettextToI18next } = require('i18next-conv');
// Convert .po files to i18next files
fs.readdir(path.join(__dirname, '..', '..', 'po'), (err, files) => {
if (err) {
return console.log(err)
}
for (const file of files) {
if (file.endsWith('.po')) {
const lang = file.replace(/\.po$/, '')
const output = path.join(__dirname, '..', 'static', 'translations', `${lang}.json`)
fs.readFile(path.join(__dirname, '..', '..', 'po', file), (err, content) => {
if (err) {
return console.log(err)
}
gettextToI18next(lang, content).then(res => {
fs.writeFile(output, res, err => {
if (err) {
console.log(err)
}
})
})
})
}
}
})

View file

@ -70,6 +70,7 @@
"friendly-errors-webpack-plugin": "^1.1.3",
"html-webpack-plugin": "^2.28.0",
"http-proxy-middleware": "^0.17.3",
"i18next-conv": "^6.0.0",
"inject-loader": "^3.0.0",
"karma": "^1.4.1",
"karma-coverage": "^1.1.1",

View file

@ -0,0 +1 @@
{}

View file

@ -0,0 +1 @@
{}