Created
October 21, 2017 12:38
-
-
Save gmarcos87/565d57747b30e1755046002137228562 to your computer and use it in GitHub Desktop.
Identify missing and missing keys in different languages by taking one as a reference
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
const genericFile = require('./locales/en.json') | |
const colors = require('colors') | |
// Load all translation in locales folder | |
let translations = {} | |
require('fs').readdirSync('./locales/').forEach((file) => { | |
if (file.match(/\.json$/) !== null) { | |
let name = file.replace('.json', '') | |
translations[name] = require('./locales/' + file) | |
} | |
}); | |
const missing = (master, slave) => { | |
const slaveKeys = Object.keys(slave) | |
return Object.keys(master).filter(key => slaveKeys.indexOf(key)=== -1) | |
}; | |
const init = () => { | |
console.log(colors.bold.underline('Translations differences')) | |
Object.keys(translations) | |
.forEach((lang) => { | |
const translationsMissing = missing(genericFile,translations[lang]) | |
const translationsSurplus = missing(translations[lang],genericFile) | |
//Print Output | |
console.log(colors.bold(' ./locales/' + lang + '.json')) | |
translationsMissing.map( x => console.log(colors.green(' +++ '+ x))) | |
translationsSurplus.map( x => console.log(colors.red(' --- '+ x))) | |
}); | |
}; | |
init(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment