Fix Spanish (Latin America) being missing from in-app language selection

(cherry picked from commit 290efb0283)
This commit is contained in:
arkon 2023-03-24 22:58:29 -04:00
parent 934ed0551a
commit 10973bf3cd

View File

@ -3,25 +3,22 @@ import org.gradle.api.Task
import org.gradle.api.tasks.TaskProvider import org.gradle.api.tasks.TaskProvider
import org.gradle.kotlin.dsl.TaskContainerScope 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> { fun TaskContainerScope.registerLocalesConfigTask(project: Project): TaskProvider<Task> {
return with(project) { return with(project) {
register("generateLocalesConfig") { register("generateLocalesConfig") {
val emptyResourcesElement = "<resources>\\s*</resources>|<resources/>".toRegex()
val valuesPrefix = "values-?".toRegex()
val languages = fileTree("$projectDir/src/main/res/") val languages = fileTree("$projectDir/src/main/res/")
.matching { .matching { include("**/strings.xml") }
include("**/strings.xml") .filterNot { it.readText().contains(emptyResourcesElement) }
}
.filterNot {
it.readText().contains(emptyResourcesElement)
}
.map { it.parentFile.name } .map { it.parentFile.name }
.sorted() .sorted()
.joinToString(separator = "\n") { .joinToString(separator = "\n") {
val language = it val language = it
.replace(valuesPrefix, "") .replace(valuesPrefix, "")
.replace("-r", "-") .replace("-r", "-")
.replace("+", "-")
.takeIf(String::isNotBlank) ?: "en" .takeIf(String::isNotBlank) ?: "en"
" <locale android:name=\"$language\"/>" " <locale android:name=\"$language\"/>"
} }