diff options
| author | Henry Jameson <me@hjkos.com> | 2018-09-06 21:59:20 +0300 |
|---|---|---|
| committer | Henry Jameson <me@hjkos.com> | 2018-09-06 21:59:20 +0300 |
| commit | dbd010abd4ad75fa946e72117bbb10ec80e14ee0 (patch) | |
| tree | 937a5338a25d018ac9c66e77c4522dadb6be28df | |
| parent | b4a5fddea8c233d50fe24806a3b87b4327a34613 (diff) | |
a tool to check what's missing from a language
| -rwxr-xr-x | src/i18n/compare.js | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/i18n/compare.js b/src/i18n/compare.js new file mode 100755 index 00000000..1e8715f3 --- /dev/null +++ b/src/i18n/compare.js @@ -0,0 +1,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) |
