Skip to content

Instantly share code, notes, and snippets.

@gmarcos87
Created October 21, 2017 12:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gmarcos87/565d57747b30e1755046002137228562 to your computer and use it in GitHub Desktop.
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
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