Guest User

Untitled

a guest
Oct 22nd, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. const genericFile = require('./locales/en.json')
  2. const colors = require('colors')
  3.  
  4. // Load all translation in locales folder
  5. let translations = {}
  6. require('fs').readdirSync('./locales/').forEach((file) => {
  7. if (file.match(/\.json$/) !== null) {
  8. let name = file.replace('.json', '')
  9. translations[name] = require('./locales/' + file)
  10. }
  11. });
  12.  
  13. const missing = (master, slave) => {
  14. const slaveKeys = Object.keys(slave)
  15. return Object.keys(master).filter(key => slaveKeys.indexOf(key)=== -1)
  16. };
  17.  
  18. const init = () => {
  19. console.log(colors.bold.underline('Translations differences'))
  20.  
  21. Object.keys(translations)
  22. .forEach((lang) => {
  23. const translationsMissing = missing(genericFile,translations[lang])
  24. const translationsSurplus = missing(translations[lang],genericFile)
  25.  
  26. //Print Output
  27. console.log(colors.bold(' ./locales/' + lang + '.json'))
  28. translationsMissing.map( x => console.log(colors.green(' +++ '+ x)))
  29. translationsSurplus.map( x => console.log(colors.red(' --- '+ x)))
  30. });
  31. };
  32.  
  33. init();
Add Comment
Please, Sign In to add comment