Skip to content

Commit

Permalink
Fix locale not working
Browse files Browse the repository at this point in the history
  • Loading branch information
rbro112 committed Sep 27, 2023
1 parent 5bce254 commit f219b2b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ fun TextRowWithIconPreviewFromMain() {
@Composable
fun TextRowWithIconPreviewFromMainJustMultiPreview() {
TextRowWithIcon(
titleText = "Title",
subtitleText = "Subtitle"
titleText = stringResource(com.emergetools.snapshots.sample.R.string.sample_title),
subtitleText = stringResource(com.emergetools.snapshots.sample.R.string.sample_subtitle)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.res.Configuration
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.Density
import com.emergetools.snapshots.shared.ComposePreviewSnapshotConfig
Expand All @@ -19,11 +20,12 @@ fun SnapshotVariantProvider(

val localConfiguration = Configuration(LocalConfiguration.current).apply {
config.uiMode?.let { uiMode = it }
config.locale?.let { setLocale(Locale(it)) }
val locale = config.locale?.let { Locale(it) } ?: Locale.getDefault()
setLocale(locale)
}

val providedValues = arrayOf(
LocalConfiguration provides localConfiguration,
LocalContext provides LocalContext.current.createConfigurationContext(localConfiguration),
config.fontScale?.let { LocalDensity provides fontScaleDensity }
)
CompositionLocalProvider(
Expand Down

0 comments on commit f219b2b

Please sign in to comment.