Localization

  • 3 minutes to read

Localization is the process of translating an application's resources into a different language. DevExpress Blazor components ship with localizable resources for UI elements, such as button captions, menu items, error messages, and dialog boxes.

Localization Overview

DevExpress components in Blazor applications use the standard localization mechanism from the .NET framework - Satellite Resource Assemblies (libraries that contain translated resources). For more information, refer to the Creating Satellite Assemblies MSDN article.

Predefined Satellite Assemblies

DevExpress components provide NuGet packages with predefined satellite resource assemblies for the following cultures:

NuGet Package Culture
DevExpress.Blazor.de German
DevExpress.Blazor.es Spanish
DevExpress.Blazor.ja Japanese
DevExpress.Blazor.ru Russian

Follow the steps below to enable localization for a culture from the table above.

  1. Configure the application as described in the Configure a Blazor Application help topic.
  2. In Visual Studio, select Tools -> NuGet Package Manager -> Manage NuGet Packages for Solution.
  3. In the invoked dialog, select the DevExpress package source. Find the DevExpress.Blazor.XX NuGet package with the required culture and install it.

    localization NuGet Packages

Satellite Assemblies for Other Cultures

To download satellite assemblies for DevExpress Blazor components that correspond to other cultures, use the DevExpress Localization Service. This service allows you to create a custom set of satellite assemblies, modify resources, and download assemblies.

Ensure that the major version of the satellite assemblies (for instance, v19.2) matches the major version of DevExpress Blazor package in the project. For more information on how to prepare and download resource assemblies, watch DevExpress Localization Service - Getting Started.

Localization Service

Follow the steps below to add downloaded assemblies to your Blazor application.

  1. Create a subdirectory in the application's EXE file directory (usually the bin\Debug\netcoreappX.X\ subdirectory) with the name that corresponds to the generated resources' culture (for example, bin\Debug\netcoreappX.X\fr to translate your application into French).
  2. Unpack an archive with resources generated by the DevExpress Localization Service and copy the DevExpress.Blazor.resources.dll file to the created subdirectory.
  3. Rebuild the application.

Change a Culture

After you added satellite assemblies to your application, all Blazor components use resources that correspond to the current culture. To change the culture in code, use an approach that corresponds to your application’s hosting model:

Blazor Server

The code below changes the culture in Blazor Server applications.

var cultureName = culture.Name;
var uri = new Uri(NavigationManager.Uri)
    .GetComponents(UriComponents.PathAndQuery, UriFormat.Unescaped);
var query = $"?culture={Uri.EscapeDataString(cultureName)}&" +
            $"redirectUri={Uri.EscapeDataString(uri)}";

NavigationManager.NavigateTo("/Culture/SetCulture" + query, forceLoad: true);

Blazor WebAssembly

To change the culture in Blazor WebAssembly applications, add the following code to Program.Main:

var result = await jsInterop.InvokeAsync<string>("blazorCulture.get");
if(result != null) {
    var culture = new CultureInfo(result);
    CultureInfo.DefaultThreadCurrentCulture = culture;
    CultureInfo.DefaultThreadCurrentUICulture = culture;
}