scripts/check-locales.jsView |
---|
| 1 | + |
| 2 | + |
| 3 | +const genericFile = require('../locales/en.json') |
| 4 | +const colors = require('colors') |
| 5 | +const Path = require('path') |
| 6 | + |
| 7 | + |
| 8 | +let translations = {} |
| 9 | +require('fs').readdirSync(Path.join(__dirname, '..', 'locales')).forEach((file) => { |
| 10 | + if (file.match(/\.json$/) !== null) { |
| 11 | + let name = file.replace('.json', '') |
| 12 | + translations[name] = require('../locales/' + file) |
| 13 | + } |
| 14 | +}) |
| 15 | + |
| 16 | +const missing = (master, slave) => { |
| 17 | + const slaveKeys = Object.keys(slave) |
| 18 | + return Object.keys(master).filter(key => slaveKeys.indexOf(key) === -1) |
| 19 | +} |
| 20 | + |
| 21 | +console.log(colors.bold.underline('Translations differences')) |
| 22 | + |
| 23 | +Object.keys(translations).forEach((lang) => { |
| 24 | + const translationsMissing = missing(genericFile, translations[lang]) |
| 25 | + const translationsSurplus = missing(translations[lang], genericFile) |
| 26 | + |
| 27 | + |
| 28 | + console.log(colors.bold(' ./locales/' + lang + '.json')) |
| 29 | + |
| 30 | + if (translationsMissing.length) { |
| 31 | + console.log(colors.green(' +++ missing translations')) |
| 32 | + console.log( |
| 33 | + translationsMissing.map(x => ' ' + JSON.stringify(x) + ': ""').join(',\n') |
| 34 | + ) |
| 35 | + } |
| 36 | + if (translationsSurplus.length) { |
| 37 | + console.log(colors.red(' --- surplus translations')) |
| 38 | + translationsSurplus.map(x => console.log(colors.red(' ' + JSON.stringify(x)))) |
| 39 | + } |
| 40 | +}) |