Skip to content

Commit

Permalink
[resources] Use first of preferred locales instead of a current on iOS (
Browse files Browse the repository at this point in the history
#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.
  • Loading branch information
terrakok committed Mar 18, 2024
1 parent 9ac23ae commit ad9c898
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ad9c898

Please sign in to comment.