32 lines
1.2 KiB
C#
32 lines
1.2 KiB
C#
|
using System;
|
||
|
using System.Net.Http;
|
||
|
using System.Threading.Tasks;
|
||
|
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
|
||
|
using Microsoft.Extensions.DependencyInjection;
|
||
|
using Microsoft.JSInterop;
|
||
|
using System.Globalization;
|
||
|
|
||
|
namespace BlazorWebassemblyI18n
|
||
|
{
|
||
|
public class Program
|
||
|
{
|
||
|
public static async Task Main(string[] args)
|
||
|
{
|
||
|
var builder = WebAssemblyHostBuilder.CreateDefault(args);
|
||
|
builder.RootComponents.Add<App>("app");
|
||
|
builder.Services.AddLocalization(options => options.ResourcesPath = "Resources");
|
||
|
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
|
||
|
var jsInterop = builder.Build().Services.GetRequiredService<IJSRuntime>();
|
||
|
var appLanguage = await jsInterop.InvokeAsync<string>("appCulture.get");
|
||
|
if (appLanguage != null)
|
||
|
{
|
||
|
CultureInfo cultureInfo = new CultureInfo(appLanguage);
|
||
|
CultureInfo.DefaultThreadCurrentCulture = cultureInfo;
|
||
|
CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;
|
||
|
}
|
||
|
|
||
|
await builder.Build().RunAsync();
|
||
|
}
|
||
|
}
|
||
|
}
|