Changed initial culture detection#63507
Merged
dariatiurina merged 3 commits intoSep 22, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This pull request changes how the initial culture is detected in Blazor WebAssembly applications. Previously, the system used the culture set after WebAssemblyHostBuilder.CreateDefault(args) ran, which was incorrect. The fix now uses the runtime-detected default culture through a new JavaScript interop method.
Key changes:
- Added a new
getApplicationCulturemethod accessible from both JavaScript and .NET to retrieve the runtime's default culture - Updated culture change detection to only check
CurrentCultureinstead of bothCurrentCultureandCurrentUICulture - Integrated the new culture retrieval method throughout the WebAssembly hosting infrastructure
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
WebAssemblyCultureProvider.cs |
Updated initialization to use runtime-detected culture and simplified culture change validation |
IInternalJSImportMethods.cs |
Added interface method for retrieving application culture |
InternalJSImportMethods.cs |
Implemented the new culture retrieval method with JS import binding |
TestInternalJSImportMethods.cs |
Added test implementation returning "en-US" for the new culture method |
MonoPlatform.ts |
Exposed the culture retrieval function in the runtime configuration |
GlobalExports.ts |
Added the culture method to the internal Blazor interface |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
javiercn
approved these changes
Sep 2, 2025
3 tasks
maraf
approved these changes
Sep 2, 2025
ilonatommy
approved these changes
Sep 3, 2025
Member
ilonatommy
left a comment
There was a problem hiding this comment.
Good job with finding a clean way of passing the config value to the managed code!
We have to wait for the runtime PR to be propagated, other than this and the minor comment, it's perfect.
This was referenced Sep 4, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changed initial culture detection
Description:
This pull request introduces support for retrieving and managing the application's culture information throughout the Blazor WebAssembly stack. The main changes include adding a new method for accessing the application culture from both JavaScript and .NET, updating initialization logic to use this value, and ensuring the culture can be accessed and tested consistently.
Logic behind change:
The previously introduced method of checking the initial culture of the application was flawed. In the meaning, it held the culture that was set after before
WebAssemblyHostBuilder.CreateDefault(args)run as initial. It was not correct. We should assume that culture that runtime detected as default. The additional change in runtime (dotnet/runtime#119269) was made to make this fix possible.We as well checked the differences between initial UI culture and the current UI culture, which is not correct, because browser and JS do not divide between UI culture and culture. Therefore some unprompted errors could've been thrown.
Changes:
getApplicationCultureand implemented it in the runtime configuration setup, allowing JavaScript to expose the application's culture to .NET.WebAssemblyCultureProviderto use the culture provided by JavaScript, falling back to invariant culture if unavailable.IInternalJSImportMethodsinterface and its implementation to include the newGetApplicationCulturemethod, enabling .NET code to retrieve the culture via interop.CurrentCultureand notCurrentUICulture, refining the conditions under which an exception is thrown for unsupported culture changes.Fixes #37258