-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
build.gradle
86 lines (77 loc) · 3.17 KB
/
build.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
plugins {
id 'com.android.application'
id 'com.github.triplet.play' version '3.8.3'
}
android {
namespace 'com.trianguloy.urlchecker'
defaultConfig {
applicationId "com.trianguloy.urlchecker"
compileSdk 34
minSdkVersion 19
targetSdkVersion 34
versionCode 34
versionName "2.16"
// generate buildconfig field with all locales
def folder = file("src/main/res") // from this folder
def prefix = "values-" // with this prefix
def translations = folder.list().toList().stream() // from all files in the folder
.filter { it.startsWith(prefix) } // keep those starting with the prefix
.filter { file("$folder.path/$it/strings.xml").exists() } // and containing a strings translation
.collect { it }
def constructor = translations.stream()
.map { it.substring(prefix.length()).replace('-r', '-') } // extract the locale code
.collect { '"' + it + '"' } // convert as 'string'
.join(',') // and concatenate with commas
buildConfigField "java.util.List<String>", 'LOCALES', "java.util.List.of(\"en\",$constructor)" // create field
// generate string resource with all translators
def translators = translations.stream() // for all translations
.map { file("$folder.path/$it/strings.xml") } // get the xml file
.map { new XmlParser().parse(it).find { it.@name == "translators" }?.text() ?: "" } // extract translators
.filter { it != "" } // filter empty
.flatMap { it.split(';').stream() } // split multiple
.map { it.strip() } // trim
.filter { it != "TrianguloY" } // remove myself
.distinct().sorted() // keep distinct and sort them
.collect { it }.join(', ') // join with commas
print "Extracted translators: $translators"
resValue "string", "all_translators", translators // create resource
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
alpha {
initWith(buildTypes.debug)
applicationIdSuffix '.alpha'
versionNameSuffix '-ALPHA'
}
evaluation {
initWith(buildTypes.debug)
applicationIdSuffix '.test'
versionNameSuffix '-TEST'
}
}
lint {
// users are free to update translations whenever
// this mean that they are not usually up to date
// and that there are usually lots of missing translations
// so we ignore missing strings
disable 'MissingTranslation'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
buildFeatures {
buildConfig true
}
}
play {
track.set("beta")
releaseName.set(android.defaultConfig.versionName + " (" + android.defaultConfig.versionCode + ")")
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
}