logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://anongit.hacktivis.me/git/pleroma-fe.git/

compare (1847B)


  1. #!/usr/bin/env node
  2. const arg = process.argv[2]
  3. if (typeof arg === 'undefined') {
  4. console.log('This is a very simple and tiny tool that checks en.json with any other language and')
  5. console.log('outputs all the things present in english but missing in foreign language.')
  6. console.log('')
  7. console.log('Usage: ./compare.js <lang> ')
  8. console.log(' or')
  9. console.log(' node ./compare.js <lang>')
  10. console.log('')
  11. console.log('Where <lang> is name of .json file containing language. For ./fi.json it should be:')
  12. console.log(' ./compare.js fi ')
  13. console.log('')
  14. console.log('Limitations: ')
  15. console.log('* This program does not work with languages left over in messages.js')
  16. console.log('* This program does not check for extra strings present in foreign language but missing')
  17. console.log(' in english.js (for now)')
  18. console.log('')
  19. console.log('There are no other arguments or options. Make an issue if you encounter a bug or want')
  20. console.log('some feature to be implemented. Merge requests are welcome as well.')
  21. process.exit()
  22. }
  23. const english = require('./en.json')
  24. const foreign = require(`./${arg}.json`)
  25. function walker (a, b, path = []) {
  26. Object.keys(a).forEach(k => {
  27. const aVal = a[k]
  28. const bVal = b[k]
  29. const aType = typeof aVal
  30. const bType = typeof bVal
  31. const currentPath = [...path, k]
  32. const article = aType[0] === 'o' ? 'an' : 'a'
  33. if (bType === 'undefined') {
  34. console.log(`Foreign language is missing ${article} ${aType} at path ${currentPath.join('.')}`)
  35. } else if (aType === 'object') {
  36. if (bType !== 'object') {
  37. console.log(`Type mismatch! English has ${aType} while foreign has ${bType} at path ${currentPath.join['.']}`)
  38. } else {
  39. walker(aVal, bVal, currentPath)
  40. }
  41. }
  42. })
  43. }
  44. walker(english, foreign)