git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Commit 3e9111306b522a46fa42a83d9e640509260fbf04

add `npm run check-locales`

#654
Matt McKegg committed on 10/28/2017, 11:32:22 AM
Parent: 9f6ed6465a3163edc4e9c2f593884cb5fea21191

Files changed

package.jsonchanged
scripts/check-locales.jsadded
package.jsonView
@@ -7,8 +7,9 @@
77 "main": "index.js",
88 "scripts": {
99 "test": "standard",
1010 "start": "electron index.js",
11+ "check-locales": "node scripts/check-locales.js",
1112 "postinstall": "npm run rebuild",
1213 "rebuild": "cross-script npm rebuild --runtime=electron \"--target=$(electron -v)\" \"--abi=$(electron --abi)\" --disturl=https://atom.io/download/atom-shell"
1314 },
1415 "author": "Secure Scuttlebutt Consortium",
@@ -70,7 +71,8 @@
7071 "suggest-box": "^2.2.3",
7172 "text-node-searcher": "^1.1.1"
7273 },
7374 "devDependencies": {
75+ "colors": "^1.1.2",
7476 "electron": "~1.8.1"
7577 }
7678 }
scripts/check-locales.jsView
@@ -1,0 +1,40 @@
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+})

Built with git-ssb-web