git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: 3e9111306b522a46fa42a83d9e640509260fbf04

Files: 3e9111306b522a46fa42a83d9e640509260fbf04 / scripts / check-locales.js

1369 bytesRaw
1// adapted from https://gist.github.com/gmarcos87/565d57747b30e1755046002137228562
2
3const genericFile = require('../locales/en.json')
4const colors = require('colors')
5const Path = require('path')
6
7// Load all translation in locales folder
8let translations = {}
9require('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
16const missing = (master, slave) => {
17 const slaveKeys = Object.keys(slave)
18 return Object.keys(master).filter(key => slaveKeys.indexOf(key) === -1)
19}
20
21console.log(colors.bold.underline('Translations differences'))
22
23Object.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