forked from leonlatsch/Photok
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
119 lines (105 loc) · 3.97 KB
/
build.gradle.kts
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import java.util.*
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
val kotlinVersion = "1.4.21"
repositories {
google()
jcenter()
}
dependencies {
classpath("com.android.tools.build:gradle:4.1.2")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
classpath("androidx.navigation:navigation-safe-args-gradle-plugin:2.3.2")
classpath("com.google.dagger:hilt-android-gradle-plugin:2.28-alpha")
classpath("com.google.android.gms:oss-licenses-plugin:0.10.2")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven("https://jitpack.io")
}
}
tasks.register("updateTranslations") {
val resPath = "app/src/main/res"
val bytes = java.io.FileInputStream(File("$resPath/values/strings.xml")).readBytes()
val enLines = String(bytes).split("\n")
var enStrings = 0
for (line in enLines) {
if (line.contains("<string")) {
enStrings++
}
}
val badges = arrayListOf<String>()
File(resPath).walk().forEach { dir ->
if (dir.isDirectory &&
dir.name.contains("values") &&
dir.name != "values"
) {
dir.walk().forEach { stringsFile ->
if (stringsFile.name == "strings.xml") {
var strings = 0
val lines = String(java.io.FileInputStream(stringsFile).readBytes()).split("\n")
for (line in lines) {
if (line.contains("<string") && !line.contains("TODO")) {
strings++
}
}
val localeName = dir.name.replace("values-", "")
val percentage = (strings.toDouble() / enStrings.toDouble()) * 100
val template = "https://img.shields.io/badge/{locale}-{percentage}{color}"
val color = when {
percentage > 99 -> "25-brightgreen"
percentage > 75 -> "25-yellow"
percentage > 50 -> "25-orange"
percentage > 0 -> "25-red"
else -> "lightgrey"
}
val localeDisplay = Locale.forLanguageTag(localeName.replace("-r", "-"))
.getDisplayName(Locale.US)
val badge = template
.replace("{locale}", localeDisplay.replace(" ", "%20"))
.replace("{percentage}", "${percentage.toInt()}%")
.replace("{color}", color)
badges.add(badge)
}
}
}
} // READ strings.xml
if (badges.isNotEmpty()) {
val readmeString = String(java.io.FileInputStream(File("README.md")).readBytes())
val readmeLines = readmeString.split("\n")
var beginIndex = 0
var endIndex = 0
var i = 0
while (i < readmeLines.size) {
if (readmeLines[i].contains("BEGIN-TRANSLATIONS")) {
beginIndex = i + 1
}
if (readmeLines[i].contains("END-TRANSLATIONS")) {
endIndex = i
}
i++
}
val prefixStrings = readmeLines.subList(0, beginIndex)
val suffixStrings = readmeLines.subList(endIndex, readmeLines.size - 1)
var badgeString = ""
badges.forEach {
badgeString += "![]($it)\n"
}
var newReadmeString = ""
prefixStrings.forEach {
newReadmeString += "$it\n"
}
newReadmeString += badgeString
suffixStrings.forEach {
newReadmeString += "$it\n"
}
if (newReadmeString.isNotEmpty()) {
File("README.md").writeText(newReadmeString)
}
}
}