forked from plepe/openstreetmap-tag-translations
-
Notifications
You must be signed in to change notification settings - Fork 0
/
distribute-tags
executable file
·63 lines (49 loc) · 1.1 KB
/
distribute-tags
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
59
60
61
62
63
#!/usr/bin/env node
const fs = require('fs')
const forEach = require('async-foreach').forEach
let all = {}
let allData = {}
/* read existing translation files in lang/ */
fs.readdir('tags', function (err, files) {
forEach(files, function (f) {
let m = f.match(/^(.*)\.json$/)
if (!m) {
return
}
let done = this.async()
fs.readFile('tags/' + f, function (f, err, contents) {
let data
try {
data = JSON.parse(contents)
} catch (e) {
return done()
}
if (!data) {
return done()
}
allData[f] = data
for (var k in data) {
all[k] = true
}
done()
}.bind(this, f))
},
allDone)
})
function allDone () {
forEach(Object.keys(allData), function (f) {
let data = allData[f]
for (var k in all) {
if (!(k in data)) {
data[k] = ''
}
}
var ret = {}
var keys = Object.keys(data)
keys.sort()
for (var i = 0; i < keys.length; i++) {
ret[keys[i]] = data[keys[i]]
}
fs.writeFile('tags/' + f, JSON.stringify(ret, null, ' ') + '\n')
})
}