Add localization support for multi-language UI
This commit introduces comprehensive localization support for the application, enabling dynamic language switching and localized UI elements. Key changes include: - Added `.resx` files for German (de-DE), English (en-US), and French (fr-FR). - Updated Razor components to use `IStringLocalizer` for dynamic string localization. - Introduced the `L(string key, string fallback)` helper method for consistent localized string retrieval with fallback support. - Implemented dynamic culture initialization in `Program.cs` via an API call to `/api/Localization/lang`. - Localized error pages, grid columns, tabs, popups, validation messages, and tooltips. - Dynamically generated privacy policy links based on the current culture. - Improved user experience with fully localized loading states, error handling, and UI labels. These changes enhance accessibility and usability, making the application more user-friendly for a global audience.
This commit is contained in:
@@ -5,9 +5,17 @@ using DevExpress.Blazor.Reporting;
|
||||
using DevExpress.XtraReports.Web.Extensions;
|
||||
using DevExpress.DataAccess.Web;
|
||||
using DevExpress.XtraReports.Services;
|
||||
using System.Globalization;
|
||||
|
||||
var builder = WebAssemblyHostBuilder.CreateDefault(args);
|
||||
|
||||
var initialCulture = await ResolveInitialCultureAsync(builder.HostEnvironment.BaseAddress);
|
||||
var cultureInfo = new CultureInfo(initialCulture);
|
||||
CultureInfo.DefaultThreadCurrentCulture = cultureInfo;
|
||||
CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;
|
||||
|
||||
builder.Services.AddLocalization();
|
||||
|
||||
// Named HttpClient for API calls (both for services and DevExpress components)
|
||||
builder.Services.AddHttpClient("EnvelopeGenerator.Server", client =>
|
||||
{
|
||||
@@ -67,3 +75,23 @@ ReportStorageWebExtension.RegisterExtensionGlobal(new InMemoryReportStorageWebEx
|
||||
var host = builder.Build();
|
||||
await FontLoader.LoadFonts(host.Services.GetRequiredService<IHttpClientFactory>(), new List<string> { "opensans.ttf" });
|
||||
await host.RunAsync();
|
||||
|
||||
static async Task<string> ResolveInitialCultureAsync(string baseAddress)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var http = new HttpClient { BaseAddress = new Uri(baseAddress) };
|
||||
var response = await http.GetAsync("/api/Localization/lang");
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
return "de-DE";
|
||||
|
||||
var value = await response.Content.ReadAsStringAsync();
|
||||
var culture = value.Trim().Trim('"');
|
||||
return string.IsNullOrWhiteSpace(culture) ? "de-DE" : culture;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return "de-DE";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user