Skip to content

Commit

Permalink
🐛 Enables language switching without redirecting to the homepage
Browse files Browse the repository at this point in the history
  • Loading branch information
guiyanakuang committed Dec 1, 2023
1 parent f3d2f23 commit 4428bd6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
23 changes: 11 additions & 12 deletions composeApp/src/commonMain/kotlin/com/clipevery/ClipeveryApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ import org.koin.core.KoinApplication

@Composable
fun ClipeveryApp(koinApplication: KoinApplication, hideWindow: () -> Unit) {
CompositionLocalProvider(
LocalKoinApplication provides koinApplication
) {
ClipeveryWindow(hideWindow)
}
}

@Composable
fun ClipeveryWindow(hideWindow: () -> Unit) {
MaterialTheme {
Box(modifier = Modifier
.background(Color.Transparent)
Expand Down Expand Up @@ -71,25 +80,15 @@ fun ClipeveryApp(koinApplication: KoinApplication, hideWindow: () -> Unit) {
.background(Color.White)
.fillMaxWidth(),
horizontalAlignment = Alignment.CenterHorizontally) {
ClipeveryCommon(koinApplication)
ClipeveryContent()
}
}
}
}
}


@Composable
fun ClipeveryCommon(koinApplication: KoinApplication) {
CompositionLocalProvider(
LocalKoinApplication provides koinApplication
) {
ClipeveryWithProvidedDependencies()
}
}

@Composable
fun ClipeveryWithProvidedDependencies() {
fun ClipeveryContent() {
val currentPage = remember { mutableStateOf(PageType.HOME) }
when (currentPage.value) {
PageType.HOME -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ fun SettingsContentUI(currentPage: MutableState<PageType>) {
MenuItem(language.name) {
copywriter.switchLanguage(language.abridge)
showMoreLanguage = false
currentPage.value = PageType.HOME
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions composeApp/src/desktopMain/kotlin/com/clipevery/i18n/I18n.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.clipevery.i18n

import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import com.clipevery.config.ConfigManager
import io.github.oshai.kotlinlogging.KotlinLogging
import java.io.FileNotFoundException
Expand All @@ -20,12 +23,12 @@ fun getText(id: String): String {
return languageMap.computeIfAbsent(en) { CopywriterImpl(en) }.getText(id)
}

open class GlobalCopywriterImpl(val configManager: ConfigManager): GlobalCopywriter {
open class GlobalCopywriterImpl(private val configManager: ConfigManager): GlobalCopywriter {

private var copywriter: Copywriter = languageMap
private var copywriter: Copywriter by mutableStateOf(languageMap
.computeIfAbsent(configManager.config.language) {
CopywriterImpl(configManager.config.language)
}
})

override fun switchLanguage(language: String) {
copywriter = languageMap.computeIfAbsent(language) { CopywriterImpl(language) }
Expand Down

0 comments on commit 4428bd6

Please sign in to comment.