Files: 3e9111306b522a46fa42a83d9e640509260fbf04 / scripts / check-locales.js
1369 bytesRaw
1 | // adapted from https://gist.github.com/gmarcos87/565d57747b30e1755046002137228562 |
2 | |
3 | const genericFile = require('../locales/en.json') |
4 | const colors = require('colors') |
5 | const Path = require('path') |
6 | |
7 | // Load all translation in locales folder |
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 | // Print Output |
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 | }) |
41 |
Built with git-ssb-web