I want to access KMP resources from a locale that ...
# multiplatform
m
I want to access KMP resources from a locale that may be different from the system default. There are resource function variants for both stringArray and string that include ResourceEnvironment as a parameter, which looks great, but there doesn't seem to be any way to create such an object since it's declared as internal. Is there a (KMP) way I can do this?
z
Its not pretty, but I typically have a platform based setLocale function that sets this. On jvm its just Locale.setDefault(x). If youre also using compose, you will need a way to invalidate composables too; key(locale) or AnimatedContent(locale) works for both.
Theres an open ticket about this as well, with some alternative approaches (that are probably better than mine). I cant find it right now though!
m
Thanks for that @Zoltan Demant. I think I saw the ticket you're talking about but it's referring to a system-wide change of locale, which is not what I want. I want to access (in this case) a StringArray from a particular locale without changing the system locale. There's a work around on the Android dev pages, but again that's for system wide change.