1
1
package com.mendhak.gradlecrowdin
2
2
3
+ import groovy.io.FileType
3
4
import org.gradle.api.DefaultTask
4
5
import org.gradle.api.tasks.TaskAction
5
6
@@ -12,16 +13,12 @@ class DownloadTranslationsTask extends DefaultTask {
12
13
def apiKey
13
14
def projectId
14
15
15
- File getDestination () {
16
- project. file(destination)
17
- }
18
-
19
16
@TaskAction
20
17
def downloadTranslations () {
21
18
22
19
// println(apiKey)
23
20
// println(projectId)
24
- println (destination)
21
+ // println(destination)
25
22
26
23
def buildSubDir = new File (project. buildDir. getPath() , " /crowdin-plugin" )
27
24
buildSubDir. mkdirs()
@@ -37,7 +34,22 @@ class DownloadTranslationsTask extends DefaultTask {
37
34
file << new URL (url). openStream()
38
35
file. close()
39
36
40
- unzipFile(translationZip, buildSubDir)
37
+ // Extract to build dir/res
38
+ unzipFile(translationZip, new File (buildSubDir, " res" ))
39
+
40
+ def list = []
41
+ def extractedDir = new File (buildSubDir, " res" )
42
+ extractedDir. eachFileRecurse (FileType . FILES ) { f ->
43
+ list << f
44
+ }
45
+
46
+ // Copy to values-XYZ in the destination folder
47
+ list. each {
48
+ def copyTo = new File (destination, " values-" + it. getParentFile(). getName() + " /" + it. getName() )
49
+ println copyTo. getPath()
50
+ new AntBuilder (). copy( file :it. getPath(),
51
+ tofile :copyTo. getPath())
52
+ }
41
53
}
42
54
43
55
def unzipFile (File zipFile , File outputFolder ){
@@ -57,7 +69,7 @@ class DownloadTranslationsTask extends DefaultTask {
57
69
String fileName = ze. getName();
58
70
File newFile = new File (outputFolder, fileName);
59
71
60
- println (" Extracting : " + newFile. getAbsoluteFile());
72
+ // println("Extracting : "+ newFile.getAbsoluteFile());
61
73
62
74
if (ze. isDirectory()){
63
75
newFile. mkdirs()
0 commit comments