Hey! I’ve tried searching for an answer in here a...
# compose
m
Hey! I’ve tried searching for an answer in here and elsewhere but I can’t find any questions about it: When fetching a string from stringResources in compose, it gives me the string for the wrong language. It seems to use the device language always, rather than Locale.getDefault(). See more details in 🧵
So our app has a language chooser. To make this work, we override
attachBaseContext
in activity, and wrap the context. This works as expected everywhere else: Locale.getDefault() returns the overriden language. Calling getString in
Fragment.onStart
(or outside onStart) returns the overriden language string However: Calling getString inside of a
Composable
block gives me the string from the device language. Doesn’t matter how I call it:
fragment.getString
,
activity.getString
, or using the Compose
stringResources
function.
a
See this thread. I think the method there still works.
m
Hey Albert, thanks for the response! So it turns out just doing the
attachBaseContext
part actually works, and my issue was 100% unrelated to Compose. It was all due to missing an important step in generating translations in our translation library that we’re using 😅 Thanks for the help anyway 🙂