-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
[iOS] Fix CurrentCulture locale to be in specific format #111032
base: main
Are you sure you want to change the base?
Conversation
Tagging subscribers to this area: @dotnet/area-system-globalization |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 1 out of 2 changed files in this pull request and generated no comments.
Files not reviewed (1)
- src/native/libs/System.Globalization.Native/pal_locale.m: Language not supported
/azp run runtime-ioslike,runtime-ioslikesimulator,runtime-maccatalyst |
Azure Pipelines successfully started running 3 pipeline(s). |
static NSString* GetBaseName(NSString *localeIdentifier) | ||
{ | ||
NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:localeIdentifier]; | ||
NSString *languageCode = [locale objectForKey:NSLocaleLanguageCode]; | ||
return languageCode; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we know what this was done before?
The PR description should be updated to describe this - what we did before (has that) and why, and what we're changing it to (and why it's OK to change given the previous reasoning).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, I was trying this PR to see which test suit breaks if we switch to specific name because there are other dependencies such as SqlStrings
that were previously affected. I'll update the issue description when I finalize the code changes.
Brief history what I found:
- The switch to neutral locale names was done in [ios][HybridGlobalization] Fix default culture #104071
- In that PR, there was an assumption that our ICU also returns just neutral locale name. However, that isn't true as the ICU
uloc_getBaseName
uloc_getBaseName(defaultLocale, localeNameBuffer, ULOC_FULLNAME_CAPACITY, &status); - The problem with using Apple's system default locale is that if it's not part of https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/Globalization/IcuLocaleData.cs (e.g., en-CZ), the culture LCID number is 0x1000 (
LOCALE_CUSTOM_UNSPECIFIED
). While it seems that using LCID number to create new cultures is not recommended and using culture name is preferred, e.g.,SqlString
implementation still relies on using it, thus when LCID doesn't match with valid culture it causes failures when using someCultureInfo
APIs, e.g.,runtime/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureInfo.cs
Line 993 in 94c356d
public static CultureInfo GetCultureInfo(int culture)
I'll try to make a middle way out of this, where we use system locale if it's recognized by .NET, otherwise we use parent culture which is neutral.
/azp run runtime-ioslike,runtime-ioslikesimulator,runtime-maccatalyst |
Azure Pipelines successfully started running 3 pipeline(s). |
On iOS (and other apple mobile platforms), we are taking the system default culture and using it inside .NET as
CultureInfo.CurrentCulture
. Previously, the system default culture was truncated into neutral culture format (only language). This PR reverts the previous change and preserves the full (specific = language-region) culture locale format.A test was added to
CurrentCultureTests
to assert this behavior.