Files: dbc70f118c722afddd6784213eeafb58b27c0bc1 / scripts / check-locales.js
1554 bytesRaw
1 | // adapted from https://gist.github.com/gmarcos87/565d57747b30e1755046002137228562 |
2 | |
3 | var baseTranslation = 'en' |
4 | const genericFile = require('../locales/' + baseTranslation + '.json') |
5 | const colors = require('colors') |
6 | const Path = require('path') |
7 | |
8 | // Load all translation in locales folder |
9 | let translations = {} |
10 | require('fs').readdirSync(Path.join(__dirname, '..', 'locales')).forEach((file) => { |
11 | if (file.match(/\.json$/) !== null && baseTranslation + '.json' !== file) { |
12 | let name = file.replace('.json', '') |
13 | translations[name] = require('../locales/' + file) |
14 | } |
15 | }) |
16 | |
17 | const missing = (master, slave) => { |
18 | const slaveKeys = Object.keys(slave) |
19 | return Object.keys(master).filter(key => slaveKeys.indexOf(key) === -1) |
20 | } |
21 | |
22 | console.log(colors.bold.underline('Translations differences')) |
23 | console.log('Comparing with', colors.yellow(baseTranslation)) |
24 | |
25 | Object.keys(translations).forEach((lang) => { |
26 | const translationsMissing = missing(genericFile, translations[lang]) |
27 | const translationsSurplus = missing(translations[lang], genericFile) |
28 | |
29 | // Print Output |
30 | console.log() |
31 | console.log(colors.bold('./locales/' + lang + '.json')) |
32 | |
33 | if (translationsMissing.length) { |
34 | console.log(colors.green('+++ missing translations')) |
35 | console.log( |
36 | translationsMissing.map(x => ' ' + JSON.stringify(x) + ': ' + JSON.stringify(genericFile[x])).join(',\n') |
37 | ) |
38 | } |
39 | if (translationsSurplus.length) { |
40 | console.log(colors.red('--- surplus translations')) |
41 | translationsSurplus.map(x => console.log(colors.red(' ' + JSON.stringify(x)))) |
42 | } |
43 | }) |
44 |
Built with git-ssb-web