-
Notifications
You must be signed in to change notification settings - Fork 150
/
Copy pathmissing.js
58 lines (53 loc) · 1.74 KB
/
missing.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
52
53
54
55
56
57
58
import loc from './loc/loc.js'
// collect all languages
const findLang = (obj, set)=>{
// iterates object props recursively
Object.entries(obj).forEach( ([langType, string]) => {
if(langType == '$$') return
// check whether value is object or string
if(typeof string === 'object') {
// if object, iterate recursively
findLang(string, set)
} else {
// if string, add to language set
set.add(langType)
}
})
return set
}
const languages = findLang(loc, new Set())
// iterate language object recursively, print missing translations
const findmissing = (obj, currentType, path)=>{
// iterate object props recursively
Object.entries(obj).forEach( ([ key, value ]) => {
if(key == '$$') return
// check whether value is object or string
const next = path !== undefined ? `${path} ${key}` : key
if(typeof value === 'object') {
// if object, check whether object has strings as children
if(Object.entries(value).some(v => typeof v[1] === 'string')) {
// check whether a string of our language is present
if(value[currentType] == undefined &&
value['$$'] === undefined ) {
// if not, we found a missing translation
if(!missing.has(next)) missing.set(next, new Set())
missing.get(next).add(currentType)
}
} else {
// no strings as children, meaning we should iterate deeper
findmissing(value, currentType, next)
}
}
})
}
// iterate languages and find missing
console.log('Finding missing translations...')
const missing = new Map()
languages.forEach(type => {
findmissing(loc, type)
})
// print
missing.forEach((set, name)=>{
console.log(` ${name} → [${Array.from(set)}]`)
})
console.log(' done.')