Back to Devexpress

DxLocalizationService Class

blazor-devexpress-dot-blazor-dot-localization-c0a389e4.md

latest2.8 KB
Original Source

DxLocalizationService Class

Implements the base functionality for custom localization of Blazor applications.

Namespace : DevExpress.Blazor.Localization

Assembly : DevExpress.Blazor.v25.2.dll

NuGet Package : DevExpress.Blazor

Declaration

csharp
public class DxLocalizationService :
    IDxLocalizationService

Remarks

DevExpress components use the standard localization mechanism from the .NET – Satellite Resource Assemblies. For additional information, refer to the following topic: Localization.

Use the GetString(String) method to return translated strings by key.

The following code snippet implements a custom service to localize an application:

csharp
using DevExpress.Blazor.Localization;
using System.Globalization;

namespace LocalizationService.Services {
    public class LocalizationService : DxLocalizationService, IDxLocalizationService {
        string? IDxLocalizationService.GetString(string key) {
            return CultureInfo.CurrentUICulture.Name == "it-IT" ?
                LocalizationProvider.GetString(key) :
                base.GetString(key);
        }

        public static class LocalizationProvider {
            public static Dictionary<string, string> localization = new Dictionary<string, string> {
                {"DxBlazorStringId.Calendar_TodayButton", "Oggi"},
                {"DxBlazorStringId.Calendar_ClearButton", "Pulisci"},
                {"DxBlazorStringId.Scheduler_CancelButton", "Annulla"},
                /* ... */
            };

            public static string? GetString(string key) {
                localization.TryGetValue(key, out string? value);
                return value;
            }
        }
    }
}
csharp
using BlazorClientApp.Services;
using DevExpress.Blazor.Localization;

/* ... */

builder.Services.AddSingleton(typeof(IDxLocalizationService), typeof(LocalizationService));

View Example: Localize DevExpress Blazor components

Implements

IDxLocalizationService

Inheritance

Object DxLocalizationService

See Also

DxLocalizationService Members

DevExpress.Blazor.Localization Namespace