diff --git a/build.gradle.kts b/build.gradle.kts index bc71ab65..990e6e85 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -11,7 +11,7 @@ plugins { kotlin("jvm") version "1.5.21" kotlin("kapt") version "1.5.21" kotlin("plugin.serialization") version "1.5.21" - id("org.jetbrains.compose") version "1.0.0-alpha4-build310" + id("org.jetbrains.compose") version "1.0.0-alpha4-build315" id("com.github.gmazzo.buildconfig") version "3.0.2" id("org.jmailen.kotlinter") version "3.5.0" id("com.github.ben-manes.versions") version "0.39.0" @@ -135,6 +135,22 @@ tasks { } registerTachideskTasks(project) + + task("generateResourceConstants") { + val buildResources = buildConfig.forClass(project.group.toString(), "BuildResources") + + doFirst { + val langs = listOf("en") + sourceSets["main"].resources + .filter { it.name == "strings.xml" } + .drop(1) + .map { it.absolutePath.substringAfter("values-").substringBefore(File.separatorChar) } + buildResources.buildConfigField("Array", "LANGUAGES", langs.joinToString(prefix = "arrayOf(", postfix = ")") { it.wrap() }) + } + + generateBuildConfig { + dependsOn(this@task) + } + } } diff --git a/src/main/kotlin/ca/gosyer/ui/settings/SettingsGeneralScreen.kt b/src/main/kotlin/ca/gosyer/ui/settings/SettingsGeneralScreen.kt index 30bd68c9..f7da3b35 100644 --- a/src/main/kotlin/ca/gosyer/ui/settings/SettingsGeneralScreen.kt +++ b/src/main/kotlin/ca/gosyer/ui/settings/SettingsGeneralScreen.kt @@ -10,6 +10,7 @@ import androidx.compose.foundation.layout.Column import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.material.Divider import androidx.compose.runtime.Composable +import ca.gosyer.BuildResources import ca.gosyer.data.ui.UiPreferences import ca.gosyer.data.ui.model.StartScreen import ca.gosyer.ui.base.components.Toolbar @@ -47,17 +48,13 @@ class SettingsGeneralViewModel @Inject constructor( ) @Composable - fun getLanguageChoices(): Map = mapOf( - "" to stringResource("language_system_default", currentLocale.getDisplayName(currentLocale)) - ) + listOf( - "en", - "en-CA", - "fa", - "hi", - "pt-BR", - "sv", - "tam" - ).associateWith { Locale.forLanguageTag(it).getDisplayName(currentLocale) } + fun getLanguageChoices(): Map = ( + mapOf( + "" to stringResource("language_system_default", currentLocale.getDisplayName(currentLocale)) + ) + BuildResources.LANGUAGES + .associateWith { Locale.forLanguageTag(it).getDisplayName(currentLocale) } + ) + .toSortedMap(compareBy { it.lowercase() }) @Composable fun getDateChoices(): Map {