-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
Blazor Localization does not work with InteractiveServer #53707
Comments
Thank you for filing this issue. In order for us to investigate this issue, please provide a minimal repro project that illustrates the problem without unnecessary code. Please share with us in a public GitHub repo because we cannot open ZIP attachments, and don't include any confidential content. |
Here is the repo: |
I'm going to keep an 👁️ on this for possible docs work, even if only a temporary call out is needed for a framework 😈 during the 8.0 era. |
@halter73 could you please try to validate this? Thanks! |
This appears to be a bug, or at least a shortcoming, of location override using "Sensors" pane in the Chrome/Edge dev tools as described in https://www.aleksandrhovhannisyan.com/blog/changing-locale-in-chrome-with-dev-tools/. I think it was primarily intended to override the location provided by JS Sensor APIs as the name implies, but it happens to change some (but not all) of the If you look at request headers the network tab in the developer tab, you'll see that it aligns with the This is not a bug in Blazor though. That's just what happens if you override the language using the "Sensors" pane. If instead, you go to @guardrex I don't know if you want to include anything about this in our docs. Do they say anything about how to test localization? Maybe we could add something to https://learn.microsoft.com/aspnet/core/fundamentals/troubleshoot-aspnet-core-localization |
No, we don't in the Blazor glob/loc doc. We do cross-link to the main doc set article (IIRC). I'll take a closer look at this on Monday. |
BTW tho @aco-mreble ... Hisham and I have worked on the article, and we have two candidates for BWA glob/loc. I favor continuing to use local storage on the client, while Hisham likes hacking the loc cookie client-side. The article currently covers the approach that I favor. https://learn.microsoft.com/en-us/aspnet/core/blazor/globalization-localization?view=aspnetcore-8.0 The bit that pertains to BWAs is here ... If you're only trying to use interactive SSR, see this bit of the article ... ... and WRT to the discussion here about prerendering behavior, I don't have any knowledge on it. I will take a closer look on Monday. I'm off the weekend now 🎉. |
Is there an existing issue for this?
Describe the bug
When using
<Routes @rendermode="InteractiveServer"/>
in pre-rendering the correct locale from the browser is shown but after pre-rendering succceded the Fallback Locale is set again. If you disable pre-rendering the fallback locale will be set all the timesExpected Behavior
Blazor should set the correct locale for users
Steps To Reproduce
Create new Blazor Web App:
in Program.cs add
and
In
Components/App.razor
change<Routes />
tofor testing with prerender or
for testing without prerender.
In
Components/Pages/Home.razor
add this line below the page titleThen go to the website e.g. with Edge and go to Developer Tools -> Sensors -> Location and set it to "Berlin". In prerender: true some milliseconds you see the correct one, on prerender: false its allways the wrong one (en-US)
Exceptions (if any)
No response
.NET Version
8.0.101
Anything else?
Using Edge Version 121.0.2277.83 (Official build) (64-bit)
I believe I've pinpointed the issue: During the debugging of the RequestLocalizationMiddleware.Invoke method, I observed that each HttpRequest is sent with the appropriate Accept-Language header. However, the final call to this method targets
http://localhost:XXXX/_blazor
, where the header is unexpectedly set toen-US,en;q=0.9,de;q=0.8
. I'm unsure of the cause, but since this is the last invocation of the method during a user's page request, the CultureInfo.CurrentCulture ends up being reset to en-US.The text was updated successfully, but these errors were encountered: