-
Notifications
You must be signed in to change notification settings - Fork 106
/
crowdin.gradle
96 lines (85 loc) · 3.47 KB
/
crowdin.gradle
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
task uploadCrowdin(type: Exec) {
commandLine 'java', '-jar', 'crowdin-cli.jar', 'upload'
}
task downloadCrowdin(type: Exec) {
commandLine 'java', '-jar', 'crowdin-cli.jar', 'download'
}
task updateCrowdinInfo() {
def crowdinkey = ""
file("crowdin.yml").eachLine { line ->
if (line.contains("api_key")) {
line = line.substring(line.indexOf(":"))
line = line.substring(line.indexOf("\"") + 1)
crowdinkey = line.substring(0, line.indexOf("\""))
}
}
def lang
def progress
file("features/base/src/main/res/values/languages.xml").withWriter { out ->
out.println "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
out.println "<resources translatable=\"false\">"
out.println " <string-array name=\"languages\">"
new URL('https://api.crowdin.com/api/project/prayer-times-android/status?key=' + crowdinkey).eachLine { line ->
if (line.contains("<code>")) {
lang = line.substring(line.indexOf(">") + 1)
lang = lang.substring(0, lang.indexOf("<"))
lang = lang.split("-")[0]
}
if (line.contains("<translated_progress>")) {
progress = line.substring(line.indexOf(">") + 1)
progress = progress.substring(0, progress.indexOf("<"))
if (progress != "0") {
out.println " <item>" + lang + "|" + progress + "</item>"
}
}
}
out.println " </string-array>"
out.println "</resources>"
}
}
task findDuplicateStrings {
doLast {
def resources = [:]
new File("features").eachFile { feature ->
def values = new File(feature, "src/main/res/values/strings.xml")
if (!values.exists()) return
values.eachLine { line ->
def search = "<string name=\""
if (line.contains(search)) {
def name = line.substring(line.indexOf(search) + search.length())
name = name.substring(0, name.indexOf("\""))
def value = line.substring(line.indexOf(">") + 1)
if (value.contains("<"))
value = value.substring(0, value.indexOf("<"))
if (resources.containsKey(name)) {
System.err.printf("[findDuplicateStrings] String %s (%s) in %s also exists in %s\n", name, value, feature.getName(),
resources.get(name))
} else {
resources.put(name, feature.getName())
}
}
}
}
}
}
task findDuplicateResources {
doLast {
def resources = [:]
new File("features").eachFile { feature ->
def res = new File(feature, "src/main/res/")
if (!res.exists()) return
res.eachFile { file ->
if (file.name.startsWith("values")) return
file.eachFile { r ->
def name = r.name
if (resources.containsKey(name) && resources.get(name) != feature.getName()) {
System.err.printf("[findDuplicateResources] String %s in %s also exists in %s\n", name, feature.getName(),
resources.get(name))
} else {
resources.put(name, feature.getName())
}
}
}
}
}
}