Created
February 3, 2019 07:55
-
-
Save b282022/9e6adaf2219be6e39344e19e70f7f197 to your computer and use it in GitHub Desktop.
Determining keys per languages and vice versa for locale.ini file
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
// To be run in ColorMyWorld.activity directory | |
// Command: $ node keys_extractor.js | |
var fs = require('fs'); | |
function keysPerLanguage() { | |
var lines = fs.readFileSync('locale.ini', 'utf8').trim().split('\n'); | |
var currentLanguage = undefined; | |
var keysPerLanguage = {} | |
lines.forEach(function(line) { | |
if(line.startsWith('[')) { | |
currentLanguage = line.slice(1, line.length - 1); | |
keysPerLanguage[currentLanguage] = [] | |
} else { | |
keysPerLanguage[currentLanguage].push(line.split('=')[0]); | |
} | |
}); | |
return keysPerLanguage; | |
} | |
function languagesPerKey() { | |
var lines = fs.readFileSync('locale.ini', 'utf8').trim().split('\n'); | |
var keysAndLanguages = {} | |
var currentLanguage = undefined; | |
var languages = []; | |
lines.forEach(function(line) { | |
if(line === '') { | |
// Do Nothing | |
} | |
else if(line.startsWith('[')) { | |
currentLanguage = line.slice(1, line.length - 1); | |
languages.push(currentLanguage.toString()); | |
} else { | |
var key = line.split('=')[0]; | |
if(key === '') | |
console.log(line); | |
if(keysAndLanguages[key]) | |
keysAndLanguages[key].push(currentLanguage); | |
else | |
keysAndLanguages[key] = [currentLanguage]; | |
} | |
}); | |
console.log("Total Languages", languages.length); | |
console.log("Languages", languages); | |
return keysAndLanguages; | |
} | |
var p = languagesPerKey(); | |
var count = {}; | |
for(var key in p) { | |
count[key] = p[key].length; | |
} | |
for(var key in count) { | |
if(count[key] !== 10) | |
console.log(key, count[key]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment