2020-10-19 12:56:40 +00:00
|
|
|
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) });
|
2021-09-23 16:26:53 +00:00
|
|
|
builder.Services.AddSingleton(new SessionManager());
|
2020-10-19 12:56:40 +00:00
|
|
|
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;
|
2021-09-23 16:26:53 +00:00
|
|
|
CultureInfo.CurrentCulture = cultureInfo;
|
2020-10-19 12:56:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
await builder.Build().RunAsync();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|