Last active
September 3, 2021 15:07
-
-
Save bdombro/df3887ab68341158b528ab2cfe507cc6 to your computer and use it in GitHub Desktop.
scrubTranslation.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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