https://kotlinlang.org logo
#compose
Title
# compose
p

Peter

12/12/2023, 4:08 PM
scratching my head about smth dumb. How can I use
Locale.current
(
androidx.compose.ui.text.intl.Locale
) with
String.format(locale, ...)
?
is there a way to transform
androidx.compose.ui.text.intl.Locale
to
java.util.Locale
?
I guess?
java.util.Locale(androidx.compose.ui.text.intl.Locale.current.language)
j

Jonathan

12/12/2023, 5:45 PM
What do you
java.util.Locale
for? Taking a look at AndroidPlatformLocale.android.kt it looks like it uses
java.util.Locale
behind the scenes so theoretically you should be able to achieve the same functionality.
But it you needed it, you could probably use something like
java.util.Locale(Locale.current.toLanguageTag())
p

Peter

12/12/2023, 5:57 PM
I want to use it when formatting the string for example
String.format(<http://Locale.DE|Locale.DE> "TT %d", System.currentTimeMillis())
s

Stylianos Gakis

12/13/2023, 3:46 PM
I use https://github.com/HedvigInsurance/android/blob/7e85f0db5781027e32700587c32c517454[…]core-ui/src/main/kotlin/com/hedvig/android/core/ui/GetLocale.kt instead. Which should also respect things like per-app language settings and invalidates itself properly when there is a configuration change.
👍 1