Commit 428af89
authored
Fix resources regionCode crash before macOS 14; Use first of preferred locales instead of current (#5180)
`NSLocale.regionCode` is only available on macOS 14 and higher. This PR
changes the code so it works on older versions, similar to #4473 but for
macOS instead of iOS
https://developer.apple.com/documentation/foundation/nslocale/4172868-regioncode?language=objc
In addition to the fix explained above, I also applied the another fix
as on iOS here:
#4507.
I tested it with these settings:

Resulting in:
```
println(NSLocale.currentLocale().localeIdentifier) -> en_NL
println(NSLocale.preferredLanguages().first().let { NSLocale(it as String) }.localeIdentifier) -> en-GB
```
In this case I think `preferredLanguages` is the better option as
compose is interested in the actual set language, which is English (UK).
Note that there are still some additional issues explained in detail
here:
https://youtrack.jetbrains.com/issue/CMP-6614/iOS-Localization-strings-for-language-qualifiers-that-are-not-the-same-between-platforms-appear-not-translated
For this PR, I decided to just match the iOS behaviour for now, so at
least it is consistent. In the future I guess some locale mapping is
required (see my comment in YouTrack)1 parent 5870305 commit 428af89
File tree
1 file changed
+8
-3
lines changed- components/resources/library/src/macosMain/kotlin/org/jetbrains/compose/resources
1 file changed
+8
-3
lines changedLines changed: 8 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
11 | 16 | | |
12 | 17 | | |
13 | 18 | | |
| |||
24 | 29 | | |
25 | 30 | | |
26 | 31 | | |
27 | | - | |
28 | | - | |
| 32 | + | |
| 33 | + | |
29 | 34 | | |
30 | 35 | | |
31 | 36 | | |
| |||
0 commit comments