Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tarekgh
Copy link
Member

@tarekgh tarekgh commented Apr 29, 2025

Fixes #98543

This change enables support for creating CultureInfo objects using an undetermined language tag like und-US.
The root issue is that ICU's uloc_getName returns malformed names such as _US when given und-US. This fix ensures the removed language subtag und 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.

@Copilot Copilot AI review requested due to automatic review settings April 29, 2025 21:48
Copy link
Contributor

@Copilot Copilot AI left a 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;

Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-globalization
See info in area-owners.md if you want to be subscribed.

@tarekgh
Copy link
Member Author

tarekgh commented Apr 29, 2025

@mcdurdin would you be interested to test the fix when we merge it?

@tarekgh tarekgh added this to the 10.0.0 milestone Apr 29, 2025
@tarekgh
Copy link
Member Author

tarekgh commented Apr 29, 2025

CC @xadxura

@mcdurdin
Copy link

@mcdurdin would you be interested to test the fix when we merge it?

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")]

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CultureNotFoundException thrown when a keyboard with language tag und is activated
3 participants