umami/scripts/merge-messages.js

36 lines
874 B
JavaScript
Raw Normal View History

2022-11-04 05:33:37 +01:00
/* eslint-disable no-console */
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];
2023-04-17 01:34:49 +02:00
if (file === 'en-US.json') {
obj[key] = messages[key].defaultMessage;
} else {
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
});