mirror of
https://github.com/mihonapp/mihon.git
synced 2024-12-25 02:18:24 +01:00
Add task to generate locales_config.xml (#7754)
This commit is contained in:
parent
9dbc1aa7a3
commit
4291cc8eb1
3
.gitignore
vendored
3
.gitignore
vendored
@ -14,3 +14,6 @@ app/**/output.json
|
||||
|
||||
# Hebrew assets are copied on build
|
||||
app/src/main/res/values-iw/
|
||||
|
||||
# Generated
|
||||
locales_config.xml
|
@ -281,6 +281,8 @@ dependencies {
|
||||
}
|
||||
|
||||
tasks {
|
||||
val localesConfigTask = registerLocalesConfigTask(project)
|
||||
|
||||
withType<Test> {
|
||||
useJUnitPlatform()
|
||||
testLogging {
|
||||
@ -313,7 +315,7 @@ tasks {
|
||||
}
|
||||
|
||||
preBuild {
|
||||
dependsOn(formatKotlin, copyHebrewStrings)
|
||||
dependsOn(formatKotlin, copyHebrewStrings, localesConfigTask)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,7 @@
|
||||
android:hardwareAccelerated="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:localeConfig="@xml/locales_config"
|
||||
android:largeHeap="true"
|
||||
android:requestLegacyExternalStorage="true"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
|
@ -1,6 +1,14 @@
|
||||
plugins {
|
||||
`kotlin-dsl`
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinLibs.versions.kotlin.version.get()}")
|
||||
|
||||
implementation(gradleApi())
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
google()
|
||||
}
|
||||
|
7
buildSrc/settings.gradle.kts
Normal file
7
buildSrc/settings.gradle.kts
Normal file
@ -0,0 +1,7 @@
|
||||
dependencyResolutionManagement {
|
||||
versionCatalogs {
|
||||
create("kotlinLibs") {
|
||||
from(files("../gradle/kotlinx.versions.toml"))
|
||||
}
|
||||
}
|
||||
}
|
40
buildSrc/src/main/kotlin/LocalesConfigPlugin.kt
Normal file
40
buildSrc/src/main/kotlin/LocalesConfigPlugin.kt
Normal file
@ -0,0 +1,40 @@
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.api.tasks.TaskProvider
|
||||
import org.gradle.kotlin.dsl.TaskContainerScope
|
||||
|
||||
fun TaskContainerScope.registerLocalesConfigTask(project: Project): TaskProvider<Task> {
|
||||
return with(project) {
|
||||
register("generateLocalesConfig") {
|
||||
val emptyResourcesElement = "<resources>\\s*<\\/resources>|<resources\\/>".toRegex()
|
||||
val valuesPrefix = "values-?".toRegex()
|
||||
|
||||
val languages = fileTree("$projectDir/src/main/res/")
|
||||
.matching {
|
||||
include("**/strings.xml")
|
||||
}
|
||||
.filterNot {
|
||||
it.readText().contains(emptyResourcesElement)
|
||||
}
|
||||
.joinToString(separator = "\n") {
|
||||
val language = it.parentFile.name
|
||||
.replace(valuesPrefix, "")
|
||||
.takeIf(String::isNotBlank) ?: "en"
|
||||
" <locale android:name=\"$language\"/>"
|
||||
}
|
||||
|
||||
|
||||
val content = """
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<locale-config xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
$languages
|
||||
</locale-config>
|
||||
""".trimIndent()
|
||||
|
||||
val localeFile = file("$projectDir/src/main/res/xml/locales_config.xml")
|
||||
localeFile.parentFile.mkdirs()
|
||||
localeFile.writeText(content)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user