aboutsummaryrefslogtreecommitdiff
path: root/src/i18n/compare.js
blob: 1e8715f36511e97261c5cf8395968b3761710454 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/env node
const arg = process.argv[2]
const english = require('./en.json')
const foreign = require(`./${arg}.json`)

function walker (a, b, path = []) {
  Object.keys(a).forEach(k => {
    const aVal = a[k]
    const bVal = b[k]
    const aType = typeof aVal
    const bType = typeof bVal
    const currentPath = [...path, k]
    const article = aType[0] === 'o' ? 'an' : 'a'

    if (bType === 'undefined') {
      console.log(`Foreign language is missing ${article} ${aType} at path ${currentPath.join('.')}`)
    } else if (aType === 'object') {
      if (bType !== 'object') {
        console.log(`Type mismatch! English has ${aType} while foreign has ${bType} at path ${currentPath.join['.']}`)
      } else {
        walker(aVal, bVal, currentPath)
      }
    }
  })
}

walker(english, foreign)