mirror of
https://github.com/umami-software/umami.git
synced 2025-12-08 05:12:36 +01:00
New language build process.
This commit is contained in:
parent
3ed366ba6d
commit
6ea1bd1353
11 changed files with 618 additions and 1663 deletions
27
scripts/format-lang.js
Normal file
27
scripts/format-lang.js
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const prettier = require('prettier');
|
||||
|
||||
const src = path.resolve(__dirname, '../lang');
|
||||
const dest = path.resolve(__dirname, '../lang-formatted');
|
||||
const files = fs.readdirSync(src);
|
||||
|
||||
if (!fs.existsSync(dest)) {
|
||||
fs.mkdirSync(dest);
|
||||
}
|
||||
|
||||
files.forEach(file => {
|
||||
const lang = require(`../lang/${file}`);
|
||||
const keys = Object.keys(lang).sort();
|
||||
|
||||
const formatted = keys.reduce((obj, key) => {
|
||||
obj[key] = { defaultMessage: lang[key] };
|
||||
return obj;
|
||||
}, {});
|
||||
|
||||
const json = prettier.format(JSON.stringify(formatted), { parser: 'json' });
|
||||
|
||||
fs.writeFileSync(path.resolve(dest, file), json);
|
||||
|
||||
console.log(path.resolve(src, file), '->', path.resolve(dest, file));
|
||||
});
|
||||
30
scripts/merge-lang.js
Normal file
30
scripts/merge-lang.js
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const prettier = require('prettier');
|
||||
const root = require('../lang/en-US.json');
|
||||
|
||||
const dir = path.resolve(__dirname, '../lang');
|
||||
const files = fs.readdirSync(dir);
|
||||
const keys = Object.keys(root).sort();
|
||||
|
||||
files.forEach(file => {
|
||||
const lang = require(`../lang/${file}`);
|
||||
|
||||
console.log(`Merging ${file}`);
|
||||
|
||||
const merged = keys.reduce((obj, key) => {
|
||||
const message = lang[key];
|
||||
|
||||
obj[key] = message || root[key];
|
||||
|
||||
if (!message) {
|
||||
console.log(`Added key ${key}`);
|
||||
}
|
||||
|
||||
return obj;
|
||||
}, {});
|
||||
|
||||
const json = prettier.format(JSON.stringify(merged), { parser: 'json' });
|
||||
|
||||
fs.writeFileSync(path.resolve(dir, file), json);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue