dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.16k stars 4.71k forks source link

[Blazor WASM] CultureInfo.DisplayName not consistent #55348

Closed enricobenedos closed 2 years ago

enricobenedos commented 3 years ago

Describe the bug

CultureInfo DisplayName property does not return a consistent value in Blazor WASM projects.

To Reproduce

Example:

var enCulture = new CultureInfo("en-US");
Console.WriteLine(enCulture.DisplayName);

Actual Value en (US)

Expected Value English (United States) (as described in https://docs.microsoft.com/en-us/dotnet/api/system.globalization.cultureinfo.displayname?view=net-5.0)

Exceptions (if any)

No exceptions.

Further technical details

Runtime Environment: OS Name: Windows OS Version: 10.0.19043 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\5.0.301\

Host (useful for support): Version: 5.0.7 Commit: 556582d964

.NET SDKs installed: 5.0.301 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.All 2.1.28 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.28 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.28 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.16 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

- The IDE (VS / VS Code/ VS4Mac) you're running on, and its version

Microsoft Visual Studio Professional 2019 Version 16.10.3

javiercn commented 3 years ago

@enricobenedos thanks for contacting us.

Have you setup <InvariantGlobalization>false</InvariantGlobalization> in your MSBuild project file?

enricobenedos commented 3 years ago

This is my project file with the new InvariantGlobalization as suggested:

<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
    <DockerfileContext>.</DockerfileContext>
    <AssemblyVersion>0.1.0.0</AssemblyVersion>
    <FileVersion>0.1.0.0</FileVersion>
    <Version>0.1.0</Version>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Blazored.LocalStorage" Version="4.1.1" />
    <PackageReference Include="FmsAgvShared" Version="1.10.2" />
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.7" />
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="5.0.7" />
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.7" PrivateAssets="all" />
    <PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="5.0.7" />
    <PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
    <PackageReference Include="Microsoft.Extensions.Localization" Version="5.0.7" />
    <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.13" />
    <PackageReference Include="NetTopologySuite.IO.GeoJSON4STJ" Version="2.1.1" />
    <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.11.1" />
    <PackageReference Include="System.Net.Http.Json" Version="5.0.0" />
    <PackageReference Include="Telerik.UI.for.Blazor" Version="2.24.1" />
  </ItemGroup>

  <PropertyGroup>
    <BlazorWebAssemblyLoadAllGlobalizationData>true</BlazorWebAssemblyLoadAllGlobalizationData>
    <UserSecretsId>02d32efe-6558-4f81-b5a4-b35602ac9c1d</UserSecretsId>
    <InvariantGlobalization>false</InvariantGlobalization>
  </PropertyGroup>  

</Project>

but nothing has changed.

dotnet-issue-labeler[bot] commented 3 years ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

svick commented 3 years ago

Blazor WASM has its own cut-down version of culture data, and, as I understand it, that excludes culture names. (Though that article does not explicitly mention DisplayName for some reason.) I think that explains the behavior you see.

enricobenedos commented 3 years ago

Hi @svick, probably you are right. But I think that Blazor WASM as frontend framework cannot miss the DisplayName feature. I understand that it is for performance purposes but at this point I think that it can be solved using an adjunctive dependency that include the right cultures names. So every developer can decide if include it on his projects.

ilonatommy commented 2 years ago

This is a dupe of https://github.com/dotnet/runtime/issues/44739 let's keep the discussion there.