Skip to content

Instantly share code, notes, and snippets.

@bdombro
Last active September 3, 2021 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bdombro/df3887ab68341158b528ab2cfe507cc6 to your computer and use it in GitHub Desktop.
Save bdombro/df3887ab68341158b528ab2cfe507cc6 to your computer and use it in GitHub Desktop.
scrubTranslation.js
/**
* This CLI script will scrub/delete a translation from all translation files
*/
const path = require('path');
const fs = require('fs');
const execSync = require('child_process').execSync;
const toDelete = process.argv[2];
const localsDir = path.join(__dirname, '../src/i18n/locales');
const sourcePath = path.join(__dirname, '../src/i18n/source/strings.json');
let deleted = 0;
scrubPath(sourcePath);
for (const l of fs.readdirSync(localsDir)) {
const localePath = path.resolve(`${localsDir}/${l}/strings.json`);
scrubPath(localePath);
}
// eslint-disable-next-line no-console
console.log(`Deleted ${deleted} strings`);
function scrubPath(localePath) {
const translations = JSON.parse(fs.readFileSync(localePath, 'utf8'));
const before = Object.keys(translations).length;
delete translations[toDelete];
const after = Object.keys(translations).length;
deleted += before - after;
fs.writeFileSync(localePath, JSON.stringify(translations, null, 2), 'utf8');
execSync(`npx prettier --write ${localePath}`);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment