Question

.NET 8 Blazor WebAssembly Standalone App project "az-AZ" culture not work

.NET 8 Blazor WebAssembly Standalone App project I added "az-AZ" culture to Program.cs file but it does not work. But other languages work.

Program.cs

using BlazorApp1;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using System.Globalization;

var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");

builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });

CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("az-AZ");
CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("az-AZ");

await builder.Build().RunAsync();

BlazorApp1

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

  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
      <BlazorWebAssemblyLoadAllGlobalizationData>true</BlazorWebAssemblyLoadAllGlobalizationData>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.2" />
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.2" PrivateAssets="all" />
      
  </ItemGroup>

</Project>
 4  120  4
1 Jan 1970

Solution

 0

I found answer from Microsoft and it works. https://github.com/dotnet/runtime/issues/104717

"az" is not included by default in WASM app internalization data, see: available cultures.

BlazorWebAssemblyLoadAllGlobalizationData works only for Blazor WASM app. It loads all cultures from the "available cultures" list mentioned above. An equivalent in WASM app is <WasmIcuDataFileName>icudt_custom.dat</WasmIcuDataFileName> doc.

If you want to add any culture that is not added to "available cultures" cultures list (e.g. "az-Latn-AZ"), you should follow custom ICU instruction and use your own version of icu file, populating WasmIcuDataFileName with its name.

2024-07-16
Khalig Heydarov