git ssb

10+

Matt McKegg / patchwork



Tree: dd24bd09326e63d0e8ff74129b65f7356a8c2538

Files: dd24bd09326e63d0e8ff74129b65f7356a8c2538 / scripts / check-locales.js

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