Localization

localization

Overview

The Localization module switches the system interface between languages. It is based on BootstrapBlazor's localization mechanism: the CultureChooser component in the upper-right corner selects the language, and the change takes effect immediately without restarting the application.

Usage

Enabling Localization

Configure in Program.cs:

builder.AddEasyAdminBlazor(new EasyAdminBlazorOptions
{
    EnableLocalization = true,
    ...
});

Switching Languages

Click the target language in the language selector at the upper-right corner of the page, and the interface language switches immediately.

Adding a New Language

No code modification is needed. Simply add the corresponding translation resources to the language resource files. BootstrapBlazor will automatically read and display the available language options.

Language packs live in two places:

  • Main pack: EasyAdminBlazor/Locales/{culture}.json, root node EasyAdminBlazor.Common, for text shared by the framework and several extensions;
  • Extension pack: Extensions/EasyAdminBlazor.{Extension}/Locales/{culture}.json, also using the EasyAdminBlazor.Common root node, for text and entity blocks specific to that extension. When the extension calls AddEasyAdminBlazorAssembly, the framework adds it to JsonLocalizationOptions.AdditionalJsonAssemblies and merges it into CommonLocalizer. The repository-level Directory.Build.targets embeds Locales/*.json automatically; standalone projects need the explicit csproj items.

Add a language in both places. If an extension does not provide a culture, the main pack (and finally the Chinese key itself) is used as a fallback.

Configuration

if (options.EnableLocalization)
{
    builder.Services.AddRequestLocalization<IOptionsMonitor<BootstrapBlazorOptions>>((localizerOption, blazorOption) =>
    {
        var supportedCultures = blazorOption.CurrentValue.GetSupportedCultures();
        localizerOption.SupportedCultures = supportedCultures;
        localizerOption.SupportedUICultures = supportedCultures;
    });
}
  • CultureChooser — Language switching UI component
  • CommonLocalizer — Localization service
  • BootstrapBlazorOptions — Configures the list of supported languages