dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.48k stars 10.04k forks source link

Blazor: Safari HTTP_ACCEPT_LANGUAGE header is not identified correctly > automated translations are not working #27368

Open steamonimo opened 4 years ago

steamonimo commented 4 years ago

Describe the bug

On Edge, Chrome and Firefox (for Windows and macOS) the automated translation via IStringLocalizer in Blazor project will just work fine. The problem is visible with Safari on iOS (14.1) and macOS. Here Safari will always fall back to the EN Translation.

To Reproduce

Set the GUI of your device to a language different from EN - for example choose DE. Then open blazor page with active translations for EN and DE. Here Safari on iOS (14.1) and macOS will just show the EN translation.

Exceptions (if any)

Firefox on macOS seems to use a different HTTP_ACCEPT_LANGUAGE header. Therefore it will show the DE Translation as expected.

Further technical details

Laufzeitumgebung: OS Name: Windows OS Version: 10.0.19041 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\3.1.403\

Host (useful for support): Version: 3.1.9 Commit: 774fc3d6a9

.NET Core SDKs installed: 2.1.402 [C:\Program Files\dotnet\sdk] 2.1.403 [C:\Program Files\dotnet\sdk] 2.1.500 [C:\Program Files\dotnet\sdk] 2.1.503 [C:\Program Files\dotnet\sdk] 2.1.505 [C:\Program Files\dotnet\sdk] 2.1.801 [C:\Program Files\dotnet\sdk] 2.1.802 [C:\Program Files\dotnet\sdk] 3.1.101 [C:\Program Files\dotnet\sdk] 3.1.201 [C:\Program Files\dotnet\sdk] 3.1.400 [C:\Program Files\dotnet\sdk] 3.1.403 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

ghost commented 4 years ago

Thanks for contacting us. We're moving this issue to the Next sprint planning milestone for future evaluation / consideration. We will evaluate the request when we are planning the work for the next milestone. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

mkArtakMSFT commented 3 years ago

Hi. Thanks for contacting us. We're closing this issue as there was not much community interest in this ask for quite a while now. You can learn more about our triage process and how we handle issues by reading our Triage Process writeup.

steamonimo commented 3 years ago

So according to the "community" the iPhone users (30% of all mobile users) are not important?

steamonimo commented 3 years ago

@pranavkm What feedback do you needed?

pranavkm commented 3 years ago

Sorry, I posted this in the other issue you filed:

@steamonimo can you share your network log that indicates the header is being used? Accept-Language is the standard header used for sending the user's language (which ASP.NET Core's localization supports) and we verified that Safari v14 continues to use this header.

steamonimo commented 3 years ago

@pranavkm In my opinion the accept-language header is different in safari in comparison to firefox and chrome. I assume the following is the root cause of the problem. If your regional setting is german (de-de) then browsers will sent the headers like this:

chrome and firefox: accept-language: de,en-US;q=0.7,en;q=0.3

safari: accept-language: de-de

The problem is that at least the simplification to just "de" is missing. Furthermore the potential fallback to "en" is missing. [You could also argue that chrome and firefox should send "de,de-de;q=0.6,en-US;q=0.3,en;q=0.1"].

In my dotnet translations I just use "de" because my translation should be valid for german ("de-de") and swiss ("de-ch"). This works for chrome and firefox because they accept "de" as well. So dotnet and blazor should read "de-de" as "de;de-de" to work with "de" translations as well.

ghost commented 3 years ago

Thanks for contacting us. We're moving this issue to the Next sprint planning milestone for future evaluation / consideration. We will evaluate the request when we are planning the work for the next milestone. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

PeterOscarsson commented 3 years ago

@pranavkm @steamonimo I do not know if this is still an open problem but I have the same issue, and have nailed it down to the difference that Safari is NOT sending the Accept-Language header on the request to upgrade the connection to web socket, (url: ws://...../_blazor?id=....) therefore the ASPNET middleware will fallback to the default language. It is sending all cookies though so I work on a solution that sets the language cookie on initial request.