-
Notifications
You must be signed in to change notification settings - Fork 43
/
fetch_crowdin_l10n.groovy
42 lines (38 loc) · 1.36 KB
/
fetch_crowdin_l10n.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
def branch = properties['crowdin.branch']
def locale = properties['crowdin.locale']
def baseDir = properties['project.basedir']
def url = "https://crowdin.com/backend/download/project/bonita/${locale}.zip"
def output = File.createTempFile("${locale}_locale", '.zip')
println "Downloading localization archive for $locale..."
redirectFollowingDownload(url, output)
println "Archived downloaded to $output"
def zipFile = new java.util.zip.ZipFile(output)
zipFile.entries().findAll{ !it.directory && it.name.startsWith("${branch}/studio/community/") }.each {
def filePath = it.name.replace("${branch}/studio/community/", '')
def target = new File(baseDir, filePath)
if(target.parentFile.exists()) {
if(!target.exists()) {
target.createNewFile()
}
target.withDataOutputStream { os->
println "Writing $target"
os << zipFile.getInputStream(it)
}
}
}
def redirectFollowingDownload(String url, File outputFile) {
while(url) {
new URL(url).openConnection().with { conn ->
conn.instanceFollowRedirects = false
url = conn.getHeaderField( "Location" )
if( !url ) {
outputFile.withOutputStream { out ->
conn.inputStream.with { inp ->
out << inp
inp.close()
}
}
}
}
}
}