mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-21 20:47:03 -05:00
Generate locales_config.xml in build dir
This commit is contained in:
parent
777ae2461e
commit
ac41bffdc9
4 changed files with 16 additions and 11 deletions
|
@ -15,6 +15,7 @@ import org.gradle.kotlin.dsl.the
|
|||
import org.gradle.kotlin.dsl.withType
|
||||
import org.jetbrains.kotlin.compose.compiler.gradle.ComposeCompilerGradlePluginExtension
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
import java.io.File
|
||||
|
||||
val Project.androidx get() = the<LibrariesForAndroidx>()
|
||||
val Project.compose get() = the<LibrariesForCompose>()
|
||||
|
@ -106,3 +107,5 @@ internal fun Project.configureTest() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
val Project.generatedBuildDir: File get() = project.layout.buildDirectory.asFile.get().resolve("generated/mihon")
|
||||
|
|
|
@ -3,10 +3,11 @@ package mihon.buildlogic.tasks
|
|||
import org.gradle.api.Project
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.api.tasks.TaskProvider
|
||||
import java.io.File
|
||||
|
||||
private val emptyResourcesElement = "<resources>\\s*</resources>|<resources/>".toRegex()
|
||||
private val emptyResourcesElement = "<resources>\\s*</resources>|<resources\\s*/>".toRegex()
|
||||
|
||||
fun Project.getLocalesConfigTask(): TaskProvider<Task> {
|
||||
fun Project.getLocalesConfigTask(outputResourceDir: File): TaskProvider<Task> {
|
||||
return tasks.register("generateLocalesConfig") {
|
||||
val locales = fileTree("$projectDir/src/commonMain/moko-resources/")
|
||||
.matching { include("**/strings.xml") }
|
||||
|
@ -16,7 +17,6 @@ fun Project.getLocalesConfigTask(): TaskProvider<Task> {
|
|||
.replace("base", "en")
|
||||
.replace("-r", "-")
|
||||
.replace("+", "-")
|
||||
.takeIf(String::isNotBlank) ?: "en"
|
||||
}
|
||||
.sorted()
|
||||
.joinToString("\n") { "| <locale android:name=\"$it\"/>" }
|
||||
|
@ -28,10 +28,9 @@ fun Project.getLocalesConfigTask(): TaskProvider<Task> {
|
|||
|</locale-config>
|
||||
""".trimMargin()
|
||||
|
||||
file("$projectDir/src/androidMain/res/xml/locales_config.xml").apply {
|
||||
outputResourceDir.resolve("xml/locales_config.xml").apply {
|
||||
parentFile.mkdirs()
|
||||
writeText(content)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
2
i18n/.gitignore
vendored
2
i18n/.gitignore
vendored
|
@ -1,2 +0,0 @@
|
|||
# Generated
|
||||
locales_config.xml
|
|
@ -1,3 +1,4 @@
|
|||
import mihon.buildlogic.generatedBuildDir
|
||||
import mihon.buildlogic.tasks.getLocalesConfigTask
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
|
@ -21,13 +22,17 @@ kotlin {
|
|||
}
|
||||
}
|
||||
|
||||
val generatedAndroidResourceDir = generatedBuildDir.resolve("android/res")
|
||||
|
||||
android {
|
||||
namespace = "tachiyomi.i18n"
|
||||
|
||||
sourceSets {
|
||||
named("main") {
|
||||
res.srcDir("src/commonMain/resources")
|
||||
}
|
||||
val main by getting
|
||||
main.res.srcDirs(
|
||||
"src/commonMain/resources",
|
||||
generatedAndroidResourceDir,
|
||||
)
|
||||
}
|
||||
|
||||
lint {
|
||||
|
@ -40,7 +45,7 @@ multiplatformResources {
|
|||
}
|
||||
|
||||
tasks {
|
||||
val localesConfigTask = project.getLocalesConfigTask()
|
||||
val localesConfigTask = project.getLocalesConfigTask(generatedAndroidResourceDir)
|
||||
preBuild {
|
||||
dependsOn(localesConfigTask)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue