Skip to content

Commit

Permalink
Added script to compare language files [#170116509]
Browse files Browse the repository at this point in the history
This will allow us to see what is not translated and if there are missing keys.
  • Loading branch information
dougmartin committed Dec 4, 2019
1 parent a1301f9 commit 5a08e06
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions bin/compare-langs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env node

const fs = require("fs");

const langPath = "../src/code/utils/lang";
const masterLangFile = "en-US-master.json";

const langNames = {
"en-US.json": "English",
"es.json": "Spanish",
"el.json": "Greek",
"et.json": "Estonian",
"de.json": "German",
"he.json": "Hebrew",
"nb.json": "Norwegian: Bokmal",
"nn.json": "Norwegian: Nynorsk",
"pl.json": "Polish",
"tr.json": "Turkish",
"zh-TW.json": "Chinese",
};

const loadLang = (langFile) => {
const contents = fs
.readFileSync(`${langPath}/${langFile}`)
.toString()
.replace(/(\/\/.*)$/gm, "");
return JSON.parse(contents);
};

// load master
const master = loadLang(masterLangFile);
const masterKeys = Object.keys(master);

// compare all the other files
const langFiles = fs.readdirSync(langPath).filter(file => file !== masterLangFile);
langFiles.forEach((langFile) => {
const lang = loadLang(langFile);
const langKeys = Object.keys(lang);
console.log(`Comparing ${masterLangFile} with ${langFile} (${langNames[langFile]})`);
if (langFile.indexOf("en-US") === -1) {
masterKeys.forEach(masterKey => {
if (master[masterKey] === lang[masterKey]) {
console.log(` ${masterKey} is not translated in ${langFile}`);
}
})
}
masterKeys.forEach(masterKey => {
if (langKeys.indexOf(masterKey) === -1) {
console.log(` *** ${langFile} missing ${masterKey}`);
}
})
langKeys.forEach(langKey => {
if (masterKeys.indexOf(langKey) === -1) {
console.log(` *** ${masterLangFile} missing ${langKey}`);
}
})
})

0 comments on commit 5a08e06

Please sign in to comment.