-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added script to compare language files [#170116509]
This will allow us to see what is not translated and if there are missing keys.
- Loading branch information
1 parent
a1301f9
commit 5a08e06
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
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
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}`); | ||
} | ||
}) | ||
}) |