1

I'm using localization in my blazor wasm application. But when loading and trying to display the name of the cultures, it does not show as intended. By following this link https://learn.microsoft.com/en-us/aspnet/core/blazor/globalization-localization?view=aspnetcore-6.0&pivots=server#localization and many other tutorials, the displayName property should display German or French for the culture (de-De) and (fr-Fr).

But instead when I retrieve the differents cultures like this : `

Cultures = CultureInfo.GetCultures(CultureTypes.NeutralCultures).ToList();

And then displays it like this :

@foreach(var c in Cultures){
  <h1>@c.DisplayName</h1>
}

I get fr (Fr) or de (De) instead of the French/German I was expecting. Any ideas why it is not working?

PS: using .net 6.0 and VS 17.0.4

lioleveau
  • 518
  • 1
  • 6
  • 23

1 Answers1

1

Unfortunately CultureInfo.DisplayName/EnglishName/NativeName are not supported in Blazor WASM.

The easiest way to get them is an Api-call to your server to load a dictionary with { CultureInfo.Name, CultureInfo.DisplayName }

Marcel Wolterbeek
  • 3,367
  • 36
  • 48
  • Is this working for you? Because this was already set in my project and this does not work :/ – lioleveau Jan 19 '22 at 07:26
  • Unfortunately you are right @lioleveau. I use the `BlazorWebAssemblyLoadAllGlobalizationData` to solve [DateTime.TryParse with IFormatProvider does not work correct in Blazor WASM](https://github.com/dotnet/runtime/issues/46327) and I expected it to load the language names too, but is doesn't. I will correct my answer. – Marcel Wolterbeek Jan 19 '22 at 14:50
  • The issue with what you're suggesting is that the displayName is always in the current OS language, it won't change unfortunately – lioleveau Jan 21 '22 at 07:52