mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
Merge dev.
This commit is contained in:
commit
be1b2fc272
88 changed files with 4120 additions and 21010 deletions
42
scripts/merge-messages.mjs
Normal file
42
scripts/merge-messages.mjs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
/* eslint-disable no-console */
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import prettier from 'prettier';
|
||||
import messages from '../build/extracted-messages.json';
|
||||
import { createRequire } from "module";
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
const dest = path.resolve(__dirname, '../src/lang');
|
||||
const files = fs.readdirSync(dest);
|
||||
const keys = Object.keys(messages).sort();
|
||||
|
||||
/*
|
||||
This script takes extracted messages and merges them
|
||||
with the existing files under `lang`. Any newly added
|
||||
keys will be printed to the console.
|
||||
*/
|
||||
files.forEach(file => {
|
||||
const lang = require(`../src/lang/${file}`);
|
||||
|
||||
console.log(`Merging ${file}`);
|
||||
|
||||
const merged = keys.reduce((obj, key) => {
|
||||
const message = lang[key];
|
||||
|
||||
if (file === 'en-US.json') {
|
||||
obj[key] = messages[key].defaultMessage;
|
||||
} else {
|
||||
obj[key] = message || messages[key].defaultMessage;
|
||||
}
|
||||
|
||||
if (!message) {
|
||||
console.log(`* Added key ${key}`);
|
||||
}
|
||||
|
||||
return obj;
|
||||
}, {});
|
||||
|
||||
const json = prettier.format(JSON.stringify(merged), { parser: 'json' });
|
||||
|
||||
fs.writeFileSync(path.resolve(dest, file), json);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue