-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathchecktranslations.js
executable file
·51 lines (48 loc) · 1.5 KB
/
checktranslations.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env node
// This script will check wether all keys of nl.yaml exist in other translation files
// note: Dutch is the leading language here
const yaml = require('js-yaml')
const fs = require('fs')
const chalk = require('chalk')
const cheader = chalk.inverse
const cerror = chalk.red
const csuccess = chalk.green
require('./locales.js')
const locales = JSON.parse(process.env.LOCALES)
let nl
try {
nl = yaml.safeLoad(fs.readFileSync('./locales/nl.yaml', 'utf8'))
} catch (error) {
console.log(error.message)
process.exit(1)
}
console.log(cheader(' Loading language files… '))
const langs = {}
for (const locale of locales) {
if (locale[0] !== 'nl') {
try {
langs[locale[0]] = yaml.safeLoad(fs.readFileSync('./locales/' + locale[0] + '.yaml', 'utf8'))
langs[locale[0]].__language__ = locale[1]
} catch (error) {
console.log(`ERROR WHILE LOADING ${locale[0]}.yaml:\n${error.message}`)
process.exit(1)
}
}
}
console.log('…language files loaded')
console.log(cheader(' Looking for missing keys… '))
let errs = 0
Object.keys(nl).forEach(key => {
Object.keys(langs).forEach(loc => {
if (langs[loc][key] === undefined) {
errs++
console.log(cerror(` Missing in ${langs[loc].__language__}, ${loc}.yaml: ${key} `))
}
})
})
if (errs > 0) {
console.log(cheader(cerror(` ${errs} missing keys found `)))
} else {
console.log(cheader(csuccess(' Looking good! ')))
}
console.log('\n')