Skip to content

Commit ad90ca5

Browse files
authored
[release/8.0][Apple] Use NSLocale.preferredLanguages on for default locale name
1 parent e21d960 commit ad90ca5

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

src/native/libs/System.Globalization.Native/pal_locale.m

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,34 @@
1616

1717
char* DetectDefaultAppleLocaleName(void)
1818
{
19-
NSLocale *currentLocale = [NSLocale currentLocale];
20-
NSString *localeName = @"";
21-
22-
if (!currentLocale)
19+
@autoreleasepool
2320
{
24-
return strdup([localeName UTF8String]);
25-
}
21+
if (NSLocale.preferredLanguages.count > 0)
22+
{
23+
return strdup([NSLocale.preferredLanguages[0] UTF8String]);
24+
}
25+
else
26+
{
27+
NSLocale *currentLocale = [NSLocale currentLocale];
28+
NSString *localeName = @"";
2629

27-
if ([currentLocale.languageCode length] > 0 && [currentLocale.countryCode length] > 0)
28-
{
29-
localeName = [NSString stringWithFormat:@"%@-%@", currentLocale.languageCode, currentLocale.countryCode];
30-
}
31-
else
32-
{
33-
localeName = currentLocale.localeIdentifier;
34-
}
30+
if (!currentLocale)
31+
{
32+
return strdup([localeName UTF8String]);
33+
}
34+
35+
if ([currentLocale.languageCode length] > 0 && [currentLocale.countryCode length] > 0)
36+
{
37+
localeName = [NSString stringWithFormat:@"%@-%@", currentLocale.languageCode, currentLocale.countryCode];
38+
}
39+
else
40+
{
41+
localeName = currentLocale.localeIdentifier;
42+
}
3543

36-
return strdup([localeName UTF8String]);
44+
return strdup([localeName UTF8String]);
45+
}
46+
}
3747
}
3848

3949
#if defined(TARGET_MACCATALYST) || defined(TARGET_IOS) || defined(TARGET_TVOS)

0 commit comments

Comments
 (0)