In multiplatform, how can I get the current langua...
# compose
l
In multiplatform, how can I get the current language? I'm defining a CompositionLocalProvider that supplies strings but I don't know how to check which language I should use. I know there is the resource library but I prefer having resources in Kotlin files
w
you can use androidx.compose.ui.text.intl.Locale
c
The question is about Multiplatform. The first question is: what targets, you are planning to support? Then on each platform (provided for Android, System.Locale — JVM, and whatever way on Apple platform) implement “actual fun” on each platform to return the value, and define “expect fun” in Common code.
w
@CAB You can try androidx.compose.ui.text.intl.Locale in compose multiplatform. Unless you just need a library without compose
s
That one works-ish, but I don't think deals with all the intricacies of each platform. For example I know that last time I tried, using it didn't respect the per-app language settings set on the latest Android versions. It also didn't properly update itself when you experience a configuration change. Some prior discussion here https://stackoverflow.com/a/75172481 I would be happy to learn that it now works for those two cases, but afaik it doesn't.
273 Views