Refactor culture initialization logic
Moved culture initialization from App.razor to Program.cs to ensure culture settings are applied before the app starts. Removed CultureService injection and OnInitializedAsync method from App.razor. Updated LanguageSelector.razor to change language without page reload, enhancing user experience. Added System.Globalization to Program.cs for culture support.
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
@using System.Globalization
|
||||
@using EnvelopeGenerator.ReceiverUI.Services
|
||||
@inject CultureService CultureService
|
||||
|
||||
<Router AppAssembly="@typeof(Program).Assembly">
|
||||
<Found Context="routeData">
|
||||
@@ -12,12 +10,3 @@
|
||||
</LayoutView>
|
||||
</NotFound>
|
||||
</Router>
|
||||
|
||||
@code {
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
var culture = await CultureService.InitializeCultureAsync();
|
||||
CultureInfo.DefaultThreadCurrentCulture = culture;
|
||||
CultureInfo.DefaultThreadCurrentUICulture = culture;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ using DevExpress.Blazor.Reporting;
|
||||
using DevExpress.XtraReports.Web.Extensions;
|
||||
using EnvelopeGenerator.Application.Resources;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using System.Globalization;
|
||||
|
||||
var builder = WebAssemblyHostBuilder.CreateDefault(args);
|
||||
builder.RootComponents.Add<App>("#app");
|
||||
@@ -48,5 +49,12 @@ builder.Services.AddScoped<IReportProviderAsync, CustomReportProvider>();
|
||||
ReportStorageWebExtension.RegisterExtensionGlobal(new InMemoryReportStorageWebExtension());
|
||||
|
||||
var host = builder.Build();
|
||||
|
||||
// Initialize culture BEFORE running the app
|
||||
var cultureService = host.Services.GetRequiredService<CultureService>();
|
||||
var culture = await cultureService.InitializeCultureAsync();
|
||||
CultureInfo.DefaultThreadCurrentCulture = culture;
|
||||
CultureInfo.DefaultThreadCurrentUICulture = culture;
|
||||
|
||||
await FontLoader.LoadFonts(host.Services.GetRequiredService<HttpClient>(), new List<string> { "opensans.ttf" });
|
||||
await host.RunAsync();
|
||||
|
||||
@@ -43,7 +43,14 @@
|
||||
if (CultureInfo.CurrentCulture.Name != culture)
|
||||
{
|
||||
await CultureService.SetCultureAsync(culture);
|
||||
Navigation.NavigateTo(Navigation.Uri, forceLoad: true);
|
||||
|
||||
// Set culture without page reload
|
||||
var cultureInfo = new CultureInfo(culture);
|
||||
CultureInfo.DefaultThreadCurrentCulture = cultureInfo;
|
||||
CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;
|
||||
|
||||
// Navigate without reload to trigger re-render
|
||||
Navigation.NavigateTo(Navigation.Uri, forceLoad: false);
|
||||
}
|
||||
|
||||
isOpen = false;
|
||||
|
||||
Reference in New Issue
Block a user