Back to Devexpress

DxBlazorViewerLocalizerLocalizationService Class

blazor-devexpress-dot-blazor-dot-localization-e1da15f5.md

latest2.7 KB
Original Source

DxBlazorViewerLocalizerLocalizationService Class

Allows you to change localizable text at runtime.

Namespace : DevExpress.Blazor.Localization

Assembly : DevExpress.Blazor.v25.2.Viewer.dll

NuGet Package : DevExpress.Blazor.Viewer

Declaration

csharp
public class DxBlazorViewerLocalizerLocalizationService :
    IDxViewerLocalizationService,
    IDxLocalizationService

Remarks

The DxBlazorViewerStringId enumeration lists the Viewer’s localizable strings. You can implement and register a custom service to replace a specific localizable string with custom text at runtime.

Create a custom class CustomLocalizationService that inherits from the DxBlazorViewerLocalizerLocalizationService class and override the GetString method:

csharp
using DevExpress.Blazor.Reporting.Localization;
// ...
public class CustomLocalizationService: DxBlazorReportViewerLocalizerLocalizationService
{
    protected override string GetString(string key)
    {
        // The 'key' value identifies a localized string
        switch (key)
        {
            // Customize the specific resource string
            case "DxBlazorViewerStringId.Toolbar_Print":
                return "Print Document";
                break;
            // Use the built-in localization for all other strings
            default:
                return base.GetString(key);
                break;
        }
    }            
}

Register the CustomLocalizationService at application startup:

csharp
using Microsoft.AspNetCore.Hosting;
using DevExpress.Blazor.Localization;

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddScoped<IDxReportingLocalizationService, CustomLocalizationService>();
builder.Services.AddScoped<IDxViewerLocalizationService, CustomLocalizationService>();
var app = builder.Build();

Implements

IDxViewerLocalizationService

IDxLocalizationService

Inheritance

Object DxBlazorViewerLocalizerLocalizationService DxBlazorReportViewerLocalizerLocalizationService

See Also

DxBlazorViewerLocalizerLocalizationService Members

DevExpress.Blazor.Localization Namespace