public static async Task Main(string[] args) { var builder = WebAssemblyHostBuilder.CreateDefault(args); builder.RootComponents.Add("app"); builder.Services.AddTransient(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); // 增加 BootstrapBlazor 组件 builder.Services.AddBootstrapBlazor(); builder.Services.AddSingleton(); var host = builder.Build(); await GetCultureAsync(host); await host.RunAsync(); } private static async Task GetCultureAsync(WebAssemblyHost host) { var jsRuntime = host.Services.GetRequiredService(); var cultureName = await jsRuntime.InvokeAsync("$.blazorCulture.get") ?? "zh-CN"; var culture = new CultureInfo(cultureName); CultureInfo.DefaultThreadCurrentCulture = culture; CultureInfo.DefaultThreadCurrentUICulture = culture; } internal class DefaultCultureStorage : ICultureStorage { public CultureStorageMode Mode { get; set; } = CultureStorageMode.LocalStorage; }