-
Notifications
You must be signed in to change notification settings - Fork 0
/
json2csv.groovy
28 lines (23 loc) · 980 Bytes
/
json2csv.groovy
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
import groovy.io.FileType
def headers = ',,key,default,en_HLS,en_PRS,nl,nl_HLS,nl_PRS,no,no_HLS,no_PRS,se,se_HLS,se_PRS,ch,ch_HLS,ch_PRS,de,de_HLS,de_PRS'.split(",")
def languages = [:]
(new File('./i18n/')).eachFileRecurse (FileType.FILES) { file ->
def s = file.path.split(java.util.regex.Pattern.quote(System.getProperty("file.separator")))
def filename = s[s.length - 1]
//print("Found file: " + filename)
if (filename.endsWith(".json")) {
languages[filename.split('.json')[0] == 'en' ? 'default' : filename.split('.json')[0]] = (new groovy.json.JsonSlurper().parseText(file.getText('UTF-8')));
}
}
new File('./dist/language2.csv').withWriter { out ->
languages['default'].each{ k, v ->
out.print(',,')
out.print(k + ',')
headers.each{ h ->
if (h != "" && h != "key") {
out.print((languages[h][k] ? languages[h][k] : '') + ',')
}
}
out.print('\n')
}
}