Browse Source

[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.
pull/4512/head v1.6.10-dev1520
Konstantin 8 months ago committed by GitHub
parent
commit
ad9c898651
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      components/resources/library/src/iosMain/kotlin/org/jetbrains/compose/resources/ResourceEnvironment.ios.kt

4
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

Loading…
Cancel
Save