Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
android.useAndroidX=true
app.cash.paparazzi.defaultLocale=""
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="color">Couleur</string>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package app.cash.paparazzi.plugin.test

import app.cash.paparazzi.Paparazzi
import com.google.testing.junit.testparameterinjector.TestParameter
import com.google.testing.junit.testparameterinjector.TestParameterInjector
import org.junit.After
import org.junit.BeforeClass
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

class DefaultLocaleTest {

// Work-around to force system property before Paparazzi loads config.
// Not a pattern to follow or copy.
companion object {
@JvmStatic
@BeforeClass
fun setup() {
System.setProperty("app.cash.paparazzi.defaultLocale", "fr-rFR")
}
}

@get:Rule
val paparazzi = Paparazzi()

@After
fun tearDown() {
System.clearProperty("app.cash.paparazzi.defaultLocale")
}

@Test
fun `verify system property sets default locale`() {
paparazzi.snapshot(
view = paparazzi.inflate(R.layout.title_color)
)
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion paparazzi/src/main/java/app/cash/paparazzi/DeviceConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public class DeviceConfig(
public val density: Density = Density.XHIGH,
public val fontScale: Float = 1f,
public val layoutDirection: LayoutDirection = LayoutDirection.LTR,
public val locale: String? = null,
public val locale: String? = detectLocaleProperty(),
public val ratio: ScreenRatio = ScreenRatio.NOTLONG,
public val size: ScreenSize = ScreenSize.NORMAL,
public val keyboard: Keyboard = Keyboard.NOKEY,
Expand Down Expand Up @@ -917,5 +917,9 @@ public class DeviceConfig(

return map
}

internal fun detectLocaleProperty(): String? =
System.getProperty("app.cash.paparazzi.defaultLocale")
?.takeIf { it.isNotEmpty() }
}
}