2

I want to use the CultureInfo.NativeName but something is off. I always get a two letter combination as output. Ex sv (SE), en (US), es (BR). I created a completly new blazor project (WASM), ran the code there - same result, asked a colleague - same result. However, when I run it at https://dotnetfiddle.net/ I get the correct outputs.

The docs says it should work like it does in the dotnetfiddle. What can be wrong?

The issue only emerges in Blazor WASM.

Here is my test code:

var test = new CultureInfo("sv-SE");
Console.WriteLine("Native: " + test.NativeName);
Console.WriteLine("Name: " + test.Name);
Console.WriteLine("Display: " + test.DisplayName);
Console.WriteLine("English: " + test.EnglishName);

Output:

Type My results Sandbox
Native sv (SE) svenska (Sverige)
Name sv-SE sv-SE
Display sv (SE) Swedish (Sweden)
English sv (SE) Swedish (Sweden)
Cedervall
  • 1,309
  • 2
  • 13
  • 20
  • @Roe I'm not sure that's relevant here. I don't see any significant changes from the .NET 7.0 documentation (which is what OP is using): https://learn.microsoft.com/en-us/dotnet/api/system.globalization.cultureinfo?view=net-7.0 – ProgrammingLlama Mar 28 '23 at 07:40
  • Just tried it in both .NET6 and .NET7 and indeed both return the same correct native (svenska (Sverige)) value. Maybe this has to do with your countries default culture settings (which would also be weird) – Roe Mar 28 '23 at 07:43
  • 1
    I believe different installs of the operating system and even different service packs on Windows can affect the cultures available and how they're presented. It that might be what's happening here. As for how to improve the situation, I'm not sure. – ProgrammingLlama Mar 28 '23 at 07:53
  • Don't want to send you down rabbit holes, but you might check [this](https://learn.microsoft.com/en-us/dotnet/core/extensions/globalization-icu). – Christian.K Mar 28 '23 at 08:01
  • 1
    I had tested in a console application, now I wanted to make sure there wasn't a difference between Blazors CultureInfo and Console application. But I too get the shorter results inside a Blazor project. It would seem that Blazor is causing this change in data – Roe Mar 28 '23 at 08:07
  • Checked out the thread and unfortunately it's not really applicable in my case – Cedervall Mar 28 '23 at 08:35
  • 1
    Submitted an issue [here](https://github.com/dotnet/aspnetcore/issues/47464) – Cedervall Mar 28 '23 at 08:49
  • 1
    @Cedervall I think that's the right choice, keep us updated if you manage to get this resolved – Roe Mar 28 '23 at 08:51
  • As to the "why", see [this bookmark](https://learn.microsoft.com/en-us/dotnet/api/system.globalization.cultureinfo?view=net-7.0#cultureinfo-and-cultural-data) on that already linked page. Blazor Wasm does indeed use some icudt*.dat files. – H H Mar 28 '23 at 15:15

0 Answers0