1
0
mirror of https://github.com/kremalicious/umami.git synced 2024-12-23 18:04:47 +01:00
umami/scripts/merge-lang.js

31 lines
741 B
JavaScript
Raw Normal View History

2020-09-12 13:19:33 +02:00
const fs = require('fs');
const path = require('path');
const prettier = require('prettier');
2020-09-14 04:01:02 +02:00
const messages = require('../build/messages.json');
2020-09-12 13:19:33 +02:00
2020-09-14 04:01:02 +02:00
const dest = path.resolve(__dirname, '../lang');
const files = fs.readdirSync(dest);
const keys = Object.keys(messages).sort();
2020-09-12 13:19:33 +02:00
files.forEach(file => {
const lang = require(`../lang/${file}`);
console.log(`Merging ${file}`);
const merged = keys.reduce((obj, key) => {
const message = lang[key];
2020-09-14 04:01:02 +02:00
obj[key] = message || messages[key].defaultMessage;
2020-09-12 13:19:33 +02:00
if (!message) {
2020-09-12 13:26:32 +02:00
console.log(`* Added key ${key}`);
2020-09-12 13:19:33 +02:00
}
return obj;
}, {});
const json = prettier.format(JSON.stringify(merged), { parser: 'json' });
2020-09-14 04:01:02 +02:00
fs.writeFileSync(path.resolve(dest, file), json);
2020-09-12 13:19:33 +02:00
});