logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe

compare.js (1839B)


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