-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Call New GetCultureInfo API When Validating Cultures #7853
Conversation
Talked with Tarek, turns out we should be using a different API altogether: https://docs.microsoft.com/en-us/dotnet/api/system.globalization.cultureinfo.getcultureinfo?view=net-6.0#system-globalization-cultureinfo-getcultureinfo(system-string-system-boolean) |
src/Framework/Traits.cs
Outdated
/// <summary> | ||
/// https://github.com/dotnet/msbuild/issues/3897 | ||
/// </summary> | ||
public readonly bool EnableHardcodedCultureNames = Environment.GetEnvironmentVariable("MSBUILDENABLEHARDCODEDCULTURENAMES") == "1"; |
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.
I thought we were thinking opt out? But I probably misremembered.
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.
Yeah this will turn into a change wave instead of a trait
@@ -56,6 +57,21 @@ static HashSet<string> InitializeValidCultureNames() | |||
/// <returns>True if the culture is determined to be valid.</returns> | |||
internal static bool IsValidCultureString(string name) | |||
{ | |||
#if NET5_0_OR_GREATER |
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.
Prefer more descriptive ifdefs.
src/Tasks/CultureInfoCache.cs
Outdated
try | ||
{ | ||
// GetCultureInfo throws if the culture doesn't exist | ||
CultureInfo.GetCultureInfo(name, true); |
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.
This essentially says "skip the hardcoded list on net6," right? Why is that correct?
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.
The hardcoded list has always been a workaround to the fact that we didn't have an API that would specifically tell us when a culture was valid or not (CultureInfo.GetCultures(AllCultures)
wasn't made for verification purposes). It's not ideal to use the list at all, and this avoids it because starting in net5.0 this GetCultureInfo(name, true)
was introduced for specifically this purpose.
The only valid case for us to use the list moving foward would be in net472 for backwards compat when some culture or alias isn't supported. But net472 happens to work because on Windows the API we're currently using happens to contain the cultures that aren't included on linux.
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.
Does the back compat issue not apply to net6 as well?
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.
it does, NET5_0_OR_GREATER
is defined in the SDK and would apply to net5.0+. It happens around here:
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.
Should we add a test for explicit zh-CN
or whatever the most notable problematic alias was?
Co-authored-by: Rainer Sigwald <raines@microsoft.com>
@tarekgh I tried out a few test cases for aliases in codingdinosaur's writeup, and I'm seeing interesting results: The good news is they both see zh-TW as a valid culture, which is strictly improved from before 😄 any thoughts on the failing cases? are those aliases expected not to be detected? |
@benvillalobos the failing cases is because the culture name using |
@@ -218,5 +218,26 @@ public void PseudoLocalization(string culture) | |||
Assert.Equal($"MyResource.{culture}.resx", t.AssignedFiles[0].ItemSpec); | |||
Assert.Equal("MyResource.resx", t.CultureNeutralAssignedFiles[0].ItemSpec); | |||
} | |||
|
|||
/// <summary> | |||
/// Testing that certain aliases are considered valid cultures. |
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.
/// Testing that certain aliases are considered valid cultures. | |
/// Testing that certain aliases are considered valid cultures. Regression test for https://github.com/dotnet/msbuild/issues/3897. |
thanks! |
This is the first I've seen |
@benvillalobos, I told it to rerun. I suspect flakiness. @rokonec, see BenVillalobos's comment—second instance today. |
Fixes #3897
Context
Changes Made
Testing
Notes
Haven't tested this locally.