Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/8.0][Apple] Use NSLocale.preferredLanguages on for default locale name #102748

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 25 additions & 15 deletions src/native/libs/System.Globalization.Native/pal_locale.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,34 @@

char* DetectDefaultAppleLocaleName(void)
{
NSLocale *currentLocale = [NSLocale currentLocale];
NSString *localeName = @"";

if (!currentLocale)
@autoreleasepool
{
return strdup([localeName UTF8String]);
}
if (NSLocale.preferredLanguages.count > 0)
{
return strdup([NSLocale.preferredLanguages[0] UTF8String]);
}
else
{
NSLocale *currentLocale = [NSLocale currentLocale];
NSString *localeName = @"";

if ([currentLocale.languageCode length] > 0 && [currentLocale.countryCode length] > 0)
{
localeName = [NSString stringWithFormat:@"%@-%@", currentLocale.languageCode, currentLocale.countryCode];
}
else
{
localeName = currentLocale.localeIdentifier;
}
if (!currentLocale)
{
return strdup([localeName UTF8String]);
}

if ([currentLocale.languageCode length] > 0 && [currentLocale.countryCode length] > 0)
{
localeName = [NSString stringWithFormat:@"%@-%@", currentLocale.languageCode, currentLocale.countryCode];
}
else
{
localeName = currentLocale.localeIdentifier;
}

return strdup([localeName UTF8String]);
return strdup([localeName UTF8String]);
}
}
}

#if defined(TARGET_MACCATALYST) || defined(TARGET_IOS) || defined(TARGET_TVOS)
Expand Down
Loading