Migrate to multiplatform string resources (#10147)

* Migrate to multiplatform string resources

* Move plurals translations into separate files

* Fix lint check on generated files
This commit is contained in:
arkon
2023-11-18 13:54:56 -05:00
committed by GitHub
parent c39ae21f4a
commit 46e734fc8e
340 changed files with 5741 additions and 6292 deletions

View File

@ -4,23 +4,23 @@ import org.gradle.api.tasks.TaskProvider
import org.gradle.kotlin.dsl.TaskContainerScope
private val emptyResourcesElement = "<resources>\\s*</resources>|<resources/>".toRegex()
private val valuesPrefix = "values(-(b\\+)?)?".toRegex()
fun TaskContainerScope.registerLocalesConfigTask(project: Project): TaskProvider<Task> {
return with(project) {
register("generateLocalesConfig") {
val languages = fileTree("$projectDir/src/main/res/")
val languages = fileTree("$projectDir/src/commonMain/resources/MR/")
.matching { include("**/strings.xml") }
.filterNot { it.readText().contains(emptyResourcesElement) }
.map { it.parentFile.name }
.sorted()
.joinToString(separator = "\n") {
val language = it
.replace(valuesPrefix, "")
.map {
it.parentFile.name
.replace("base", "en")
.replace("-r", "-")
.replace("+", "-")
.takeIf(String::isNotBlank) ?: "en"
" <locale android:name=\"$language\"/>"
}
.sorted()
.joinToString(separator = "\n") {
" <locale android:name=\"$it\"/>"
}
val content = """
@ -30,7 +30,7 @@ $languages
</locale-config>
""".trimIndent()
val localeFile = file("$projectDir/src/main/res/xml/locales_config.xml")
val localeFile = file("$projectDir/src/androidMain/res/xml/locales_config.xml")
localeFile.parentFile.mkdirs()
localeFile.writeText(content)
}

View File

@ -10,5 +10,13 @@ extensions.configure<KtlintExtension>("ktlint") {
filter {
exclude("**/generated/**")
// For some reason this is needed for Kotlin MPP
exclude { tree ->
val path = tree.file.path
listOf("/generated/").any {
path.contains(it)
}
}
}
}