Venkataramanan Parameswaran
07/17/2024, 7:46 AMfun setLocale(locale: Locale) {
val resources = InstrumentationRegistry.getInstrumentation().targetContext.resources
val config = resources.configuration config.setLocale(locale)
resources.updateConfiguration(config, resources.displayMetrics)
}
and the test is
@Test
fun testChangeLocaleInMiddle() {
composeTestRule.onNodeWithText("Hello").assertExists()
// Change the locale to Tamil
setLocale(Locale("ta"))
// Recompose the UI
composeTestRule.activityRule.scenario.onActivity { activity ->
activity.recreate()
}
// Allow time for the activity to recreate
Thread.sleep(1000)
// Perform actions in the new locale
composeTestRule.onNodeWithText("வணக்கம்").assertExists()
}
MR3Y
07/17/2024, 1:55 PMDeviceConfigurationOverride
API, specifically Locales
fun https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[…]ride&ss=androidx%2Fplatform%2Fframeworks%2Fsupport:compose%2F if you're on Compose 1.7.
you can see this API in action in Now in android
Or use Accompanist testharness in earlier compose versions