DashboardLocalizationProvider Class
A service required for Web Dashboard localization.
Namespace: DevExpress.DashboardAspNetCore
Assembly: DevExpress.Dashboard.v24.1.AspNetCore.dll
NuGet Package: DevExpress.AspNetCore.Dashboard
Declaration
Remarks
Register the DashboardLocalizationProvider
as a singleton service:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSingleton<IDashboardLocalizationProvider, DashboardLocalizationProvider>();
var app = builder.Build();
You can also implement the IDashboardLocalizationProvider interface to create a custom localization provider.
using DevExpress.DashboardWeb;
public class DashboardWasmLocalizationProvider : IDashboardLocalizationProvider {
IServiceProvider serviceProvider;
Func<IEnumerable<string>> getJsonsListDelegate;
public DashboardWasmLocalizationProvider(IServiceProvider serviceProvider, Func<IEnumerable<string>> getJsonsListDelegate) {
this.serviceProvider = serviceProvider;
this.getJsonsListDelegate = getJsonsListDelegate;
}
async Task<Dictionary<string, string>> ReadFileAsync(HttpClient httpClient, string fileName) {
var httpRes = await httpClient.GetAsync(fileName);
if(httpRes.StatusCode == HttpStatusCode.NotFound) {
return new Dictionary<string, string>();
}
var response = await httpRes.Content.ReadAsByteArrayAsync();
return JsonSerializer.Deserialize<Dictionary<string, string>>(response);
}
public async Task<Dictionary<string, string>> GetLocalizationMessagesAsync() {
using(IServiceScope scope = serviceProvider.CreateScope()) {
HttpClient httpClient = scope.ServiceProvider.GetService<HttpClient>();
var jsons = await Task.WhenAll(getJsonsListDelegate().Select(fileName => ReadFileAsync(httpClient, fileName)));
return jsons.SelectMany(dict => dict).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
}
}
}
Use this provider when you register the Dashboard Localization Service:
public static async Task Main(string[] args) {
var builder = WebAssemblyHostBuilder.CreateDefault(args);
// ...
builder.Services.AddSingleton<IDashboardLocalizationProvider>(sp => new DashboardWasmLocalizationProvider(sp, () => {
switch(CultureInfo.CurrentUICulture.TwoLetterISOLanguageName) {
case "de":
return new string[] {
"./localization/de/dx-dashboard.de.json",
"./localization/de/dx-analytics-core.de.json",
};
default:
return new string[] { };
}
}));
}
Implements
Inheritance
Object
DashboardLocalizationProvider
See Also