The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/.scripts/fix-i18n.js

28 lines
795 B

/**
* This script will:
*
* - remove any duplicated i18n key on the same file;
* - re-order all keys based on source i18n file (en.i18n.json)
* - remove all keys not present in source i18n file
*/
const fs = require('fs');
const fg = require('fast-glob');
const fixFiles = (path, source, newlineAtEnd = false) => {
const sourceFile = JSON.parse(fs.readFileSync(`${ path }${ source }`, 'utf8'));
const sourceKeys = Object.keys(sourceFile);
fg([`${ path }/**/*.i18n.json`]).then((entries) => {
entries.forEach((file) => {
console.log(file);
const json = JSON.parse(fs.readFileSync(file, 'utf8'));
fs.writeFileSync(file, `${ JSON.stringify(json, sourceKeys, 2) }${ newlineAtEnd ? '\n' : '' }`);
});
});
};
fixFiles('./packages/rocketchat-i18n', '/i18n/en.i18n.json');