-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Make Blazor WASM respect current UI culture #62905
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
Make Blazor WASM respect current UI culture #62905
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 pull request adds support for differentiating between CultureInfo.CurrentCulture
and CultureInfo.CurrentUICulture
in Blazor WebAssembly applications, addressing issue #56824 where WASM applications previously only relied on the current culture.
Key changes:
- Enhanced
WebAssemblyCultureProvider.GetCultures
method to accept both culture and UI culture parameters - Updated culture loading logic to compute culture closure for both culture types
- Added comprehensive test coverage for the new functionality
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
WebAssemblyCultureProvider.cs |
Updated GetCultures method to handle both culture and UI culture parameters with proper closure computation |
WebAssemblyCultureProviderTest.cs |
Added unit test to verify culture closure computation with separate culture and UI culture values |
WebAssemblyLocalizationTest.cs |
Added E2E test to validate proper differentiation between CurrentCulture and CurrentUICulture |
Program.cs |
Enhanced culture configuration to support separate culture and UI culture query parameters |
LocalizedText.razor |
Added display element for UI culture to support E2E testing |
src/Components/WebAssembly/WebAssembly/src/Hosting/WebAssemblyCultureProvider.cs
Outdated
Show resolved
Hide resolved
src/Components/WebAssembly/WebAssembly/src/Hosting/WebAssemblyCultureProvider.cs
Outdated
Show resolved
Hide resolved
src/Components/WebAssembly/WebAssembly/src/Hosting/WebAssemblyCultureProvider.cs
Outdated
Show resolved
Hide resolved
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.
Good job! I added a few improvement ideas.
src/Components/WebAssembly/WebAssembly/src/Hosting/WebAssemblyCultureProvider.cs
Outdated
Show resolved
Hide resolved
src/Components/WebAssembly/WebAssembly/src/Hosting/WebAssemblyCultureProvider.cs
Outdated
Show resolved
Hide resolved
src/Components/WebAssembly/WebAssembly/test/Hosting/WebAssemblyCultureProviderTest.cs
Show resolved
Hide resolved
src/Components/WebAssembly/WebAssembly/src/Hosting/WebAssemblyCultureProvider.cs
Outdated
Show resolved
Hide resolved
src/Components/WebAssembly/WebAssembly/src/Hosting/WebAssemblyCultureProvider.cs
Show resolved
Hide resolved
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 try to implement this for general WASM in runtime ? (not just Blazor)
src/Components/WebAssembly/WebAssembly/src/Hosting/WebAssemblyCultureProvider.cs
Show resolved
Hide resolved
I was filing an issue to track this, but I just thought that it would "fundamentally" change the way this works. Currently you set the culture on the current thread (in managed code) before you start up the host and that triggers an async process when the host is built. If we were to do something for wasm, it will have to be something that gets specified before any managed code runs, doesn't it? As we can't load the dlls when you change the CultureInfo.CurrentCulture for example. |
We can't load it from synchronous code, but our startup is async. That said, runtime already detects browser culture and sets it to managed during startup. Does Blazor trigger |
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.
Good job! The failures do not look related but also, they have not failed before your PR. I triggered a rerun. If you want to look into them to asses it yourself, that's the build link: https://dev.azure.com/dnceng-public/public/_build/results?buildId=1109517&view=ms.vss-test-web.build-test-results-tab&runId=30444950&resultId=114098&paneView=history
src/Components/WebAssembly/WebAssembly/test/Hosting/WebAssemblyCultureProviderTest.cs
Outdated
Show resolved
Hide resolved
I don't think we are reading any managed info on runtime startup. We are checking 2 things:
|
I'm not sure how much it will buy us through. The issue stands that a user can do Note that it's not enough to load the culture from the browser. Apps should be able to override that with values from cookies or any other source. If we try to do it automatically, we run the risk of downloading unnecessary assemblies when the app developer sets the culture to a different value. That said, I don't think it would be a big deal, so if longer term we also want to do it on the runtime, that would be ok. I just question how much that buys us considering we need to keep the current functionality working. |
We are not reading it, but we are setting it. The env variable will influence Mono and managed too AFAIK I don't know if this would also set UI culture |
I already forgot how it was, I am checking now and that The culture flow is rather:
I don't see a feedback loop runtime -> managed, beyond env variables about globalization mode: |
We are not running this test because we don't have remote executor But I think this is the functionality we should be striving for. I think this is not just for console |
I created an RC1 doc tracking issue for this ... [RC1] Blazor WASM respects the current UI culture |
Make Blazor WASM respect current UI culture
Description
This pull request introduces support for differentiating between
CultureInfo.CurrentCulture
andCultureInfo.CurrentUICulture
in WebAssembly applications.Changes
GetCultures
method inWebAssemblyCultureProvider
to accept bothCultureInfo.CurrentCulture
andCultureInfo.CurrentUICulture
, enabling separate handling of culture and UI culture. Adjusted logic to compute culture closure for both values.WebAssemblyCultureProviderTest
to verify thatGetCultures
correctly computes the culture closure when both culture and UI culture are provided.WebAssemblyLocalizationTest
to validate that the application can differentiate betweenCurrentCulture
andCurrentUICulture
and display localized resources accordingly. To make this test work the changes were done toLocalizedText.razor
andBasicTestApp/Program.cs
.Fixes #56824