From ad9c89865153a904bdd35f2c696ff076331d092d Mon Sep 17 00:00:00 2001 From: Konstantin Date: Mon, 18 Mar 2024 10:48:19 +0100 Subject: [PATCH] [resources] Use first of preferred locales instead of a current on iOS (#4507) There is a bug on iOS: ``` NSLocale.currentLocale() -> 'en-US' NSLocale.preferredLanguages().first().let { NSLocale(it as String) } -> 'ru' ``` An equal result was expected! the first method was used in a non-compose code and another one in the compose code. The PR fixes behavior in a non-compose environment. --- .../jetbrains/compose/resources/ResourceEnvironment.ios.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/components/resources/library/src/iosMain/kotlin/org/jetbrains/compose/resources/ResourceEnvironment.ios.kt b/components/resources/library/src/iosMain/kotlin/org/jetbrains/compose/resources/ResourceEnvironment.ios.kt index 6fd9d908e9..0b5a36655f 100644 --- a/components/resources/library/src/iosMain/kotlin/org/jetbrains/compose/resources/ResourceEnvironment.ios.kt +++ b/components/resources/library/src/iosMain/kotlin/org/jetbrains/compose/resources/ResourceEnvironment.ios.kt @@ -6,7 +6,9 @@ import platform.UIKit.UIUserInterfaceStyle @OptIn(InternalResourceApi::class) internal actual fun getSystemEnvironment(): ResourceEnvironment { - val locale = NSLocale.currentLocale() + val locale = NSLocale.preferredLanguages.firstOrNull() + ?.let { NSLocale(it as String) } + ?: NSLocale.currentLocale val languageCode = locale.languageCode val regionCode = locale.objectForKey(NSLocaleCountryCode) as? String