diff --git a/presentation/src/androidMain/kotlin/ca/gosyer/ui/settings/AndroidSettingsGeneralScreen.kt b/presentation/src/androidMain/kotlin/ca/gosyer/ui/settings/AndroidSettingsGeneralScreen.kt new file mode 100644 index 00000000..6ee4c7c9 --- /dev/null +++ b/presentation/src/androidMain/kotlin/ca/gosyer/ui/settings/AndroidSettingsGeneralScreen.kt @@ -0,0 +1,9 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package ca.gosyer.ui.settings + +actual fun Any.getResourceLanguages(): Map = mapOf() \ No newline at end of file diff --git a/presentation/src/desktopMain/kotlin/ca/gosyer/ui/settings/DesktopSettingsGeneralScreen.kt b/presentation/src/desktopMain/kotlin/ca/gosyer/ui/settings/DesktopSettingsGeneralScreen.kt new file mode 100644 index 00000000..5969abfb --- /dev/null +++ b/presentation/src/desktopMain/kotlin/ca/gosyer/ui/settings/DesktopSettingsGeneralScreen.kt @@ -0,0 +1,22 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package ca.gosyer.ui.settings + +import okio.Path.Companion.toPath +import okio.asResourceFileSystem +import java.util.Locale + +actual fun Any.getResourceLanguages(): Map = this::class.java.classLoader.asResourceFileSystem().list("/localization/".toPath()) + .asSequence() + .drop(1) + .map { it.name.substringBeforeLast('.') } + .map { it.substringAfter("mokoBundle_") } + .map(String::trim) + .map { it.replace("-r", "-") } + .filterNot(String::isBlank) + .associateWith { Locale.forLanguageTag(it).getDisplayName(currentLocale) } +) \ No newline at end of file diff --git a/presentation/src/jvmMain/kotlin/ca/gosyer/ui/settings/SettingsGeneralScreen.kt b/presentation/src/jvmMain/kotlin/ca/gosyer/ui/settings/SettingsGeneralScreen.kt index b1bf06b4..4255e770 100644 --- a/presentation/src/jvmMain/kotlin/ca/gosyer/ui/settings/SettingsGeneralScreen.kt +++ b/presentation/src/jvmMain/kotlin/ca/gosyer/ui/settings/SettingsGeneralScreen.kt @@ -35,8 +35,6 @@ import cafe.adriel.voyager.core.screen.Screen import cafe.adriel.voyager.core.screen.ScreenKey import cafe.adriel.voyager.core.screen.uniqueScreenKey import me.tatarka.inject.annotations.Inject -import okio.Path.Companion.toPath -import okio.asResourceFileSystem import java.time.Instant import java.time.ZoneId import java.time.format.DateTimeFormatter @@ -61,6 +59,8 @@ class SettingsGeneralScreen : Screen { } } +expect fun Any.getResourceLanguages(): Map + class SettingsGeneralViewModel @Inject constructor( uiPreferences: UiPreferences, contextWrapper: ContextWrapper @@ -86,15 +86,7 @@ class SettingsGeneralViewModel @Inject constructor( fun getLanguageChoices(): Map = ( mapOf( "" to stringResource(MR.strings.language_system_default, currentLocale.getDisplayName(currentLocale)) - ) + this::class.java.classLoader.asResourceFileSystem().list("/localization/".toPath()) - .asSequence() - .drop(1) - .map { it.name.substringBeforeLast('.') } - .map { it.substringAfter("mokoBundle_") } - .map(String::trim) - .map { it.replace("-r", "-") } - .filterNot(String::isBlank) - .associateWith { Locale.forLanguageTag(it).getDisplayName(currentLocale) } + ) + getResourceLanguages() ) .toSortedMap(compareBy { it.lowercase() })