-
Notifications
You must be signed in to change notification settings - Fork 5k
Fix culture creation with undetermined lang tag #115166
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
base: main
Are you sure you want to change the base?
Fix culture creation with undetermined lang tag #115166
Conversation
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.
Pull Request Overview
This PR fixes the behavior of creating CultureInfo objects from undetermined language tags like "und-US" by restoring the removed "und" subtag.
- Added new tests in CultureInfoCtor.cs to validate the undetermined language tag behavior.
- Updated CultureData.Icu.cs to include the original input name in NormalizeCultureName and to restore "und" as necessary.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
File | Description |
---|---|
src/libraries/System.Runtime/tests/System.Globalization.Tests/CultureInfo/CultureInfoCtor.cs | Added tests for verifying normalization of undetermined language tags. |
src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Icu.cs | Modified NormalizeCultureName to accept the original name and restore the "und" prefix when needed. |
Comments suppressed due to low confidence (1)
src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Icu.cs:50
- Ensure that the variable 'changed' is properly declared and in scope. If it is not declared in this method or a broader scope, this line will cause a compilation error.
changed = true;
Tagging subscribers to this area: @dotnet/area-system-globalization |
@mcdurdin would you be interested to test the fix when we merge it? |
CC @xadxura |
Yes, sure, that would be great thanks. |
[InlineData("und-us", "und-US", "und-US")] | ||
[InlineData("und-us_tradnl", "und-US", "und-US_tradnl")] | ||
[InlineData("und-es-u-co-phoneb", "und-ES", "und-ES_phoneb")] | ||
[InlineData("und-es-t-something", "und-ES", "und-ES")] |
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.
Is it possible to add a test for und-fonipa
? That's a common tag for IPA, referenced on Wikipedia for example: https://en.wikipedia.org/wiki/International_Phonetic_Alphabet#IETF_language_tags
Fixes #98543
This change enables support for creating
CultureInfo
objects using an undetermined language tag likeund-US
.The root issue is that ICU's
uloc_getName
returns malformed names such as_US
when givenund-US
. This fix ensures the removed language subtagund
is preserved and restored in the result.A more comprehensive alternative—switching to
uloc_toLanguageTag
—was considered, but it may introduce compatibility and performance concerns. It would also require a broader audit of how we normalize culture names around ICU usage. We can revisit that approach if more issues like this one are discovered.