mirror of
https://github.com/mue/mue.git
synced 2026-07-22 08:17:28 +02:00
fix(dev): script didn't work
This commit is contained in:
@@ -2,24 +2,30 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const merge = require('@eartharoid/deep-merge');
|
const merge = require('@eartharoid/deep-merge');
|
||||||
|
|
||||||
|
const compareAndRemoveKeys = (json1, json2) => {
|
||||||
|
for (let key in json1) {
|
||||||
|
if (json2.hasOwnProperty(key)) {
|
||||||
|
if (typeof json1[key] === 'object' && typeof json2[key] === 'object') {
|
||||||
|
compareAndRemoveKeys(json1[key], json2[key]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
delete json1[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fs.readdirSync('../src/translations').forEach((file) => {
|
fs.readdirSync('../src/translations').forEach((file) => {
|
||||||
if (file === 'en_GB.json') {
|
if (file === 'en_GB.json') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const newdata = merge(
|
|
||||||
require('../src/translations/en_GB.json'),
|
|
||||||
require('../src/translations/' + file),
|
|
||||||
);
|
|
||||||
|
|
||||||
// remove unused strings
|
|
||||||
const en = require('../src/translations/en_GB.json');
|
const en = require('../src/translations/en_GB.json');
|
||||||
const keys = Object.keys(newdata);
|
const newdata = merge(en, require('../src/translations/' + file));
|
||||||
const enkeys = Object.keys(en);
|
|
||||||
const unused = keys.filter((key) => !enkeys.includes(key));
|
// remove strings not in english file
|
||||||
unused.forEach((key) => {
|
compareAndRemoveKeys(newdata, en);
|
||||||
delete newdata[key];
|
|
||||||
});
|
// write new file
|
||||||
fs.writeFileSync('../src/translations/' + file, JSON.stringify(newdata, null, 2));
|
fs.writeFileSync('../src/translations/' + file, JSON.stringify(newdata, null, 2));
|
||||||
|
|
||||||
// add new line
|
// add new line
|
||||||
|
|||||||
Reference in New Issue
Block a user