Localization

Localization allows to provide custom translations for localizable text in the components.

Explanation

MudBlazor itself provides English language strings for texts found in e.g. the MudDataGrid filter options. By registering a custom MudLocalizer implementation as a Service, you can provide custom translations.

Note: if Thread.CurrentThread.CurrentUICulture is English, the included English translations will be used.
Note: Currently not yet all components support localization. Contributions are welcome!

Register Service

Add the following in Program.cs to register your custom localization service. AddTransient can be replaced with TryAddTransient and the scope can be changed to Scoped or Singleton depending on your exact implementation.

using Microsoft.Extensions.DependencyInjection;
using MudBlazor;

builder.Services.AddTransient<MudLocalizer, CustomMudLocalizerImpl>();
ResX Example

An example MudLocalizer implementation using Microsoft default IStringLocalizer. Using ResX, you'll have to leave the default culture translations file empty if you want to use English as the fallback language for missing translations. Otherwise, the default culture values will be used as a fallback for all non-English languages.

using Microsoft.Extensions.Localization;
using MudBlazor;

internal class ResXMudLocalizer : MudLocalizer
{
    private IStringLocalizer _localization;

    public ResXMudLocalizer(IStringLocalizer<ResXLanguageResource> localizer)
    {
        _localization = localizer;
    }

    public override LocalizedString this[string key] => _localization[key];
}
Dictionary based Example

An example implementing MudLocalizer using a hardcoded dictionary for the translations. Note that LocalizedString.ResourceNotFound should be true, if there is no custom translation for a given key. If LocalizedString.ResourceNotFound is true, the included English localization will be used.

using System;
using System.Collections.Generic;
using System.Threading;
using Microsoft.Extensions.Localization;
using MudBlazor;

internal class DictionaryMudLocalizer : MudLocalizer
{
    private Dictionary<string, string> _localization;

    public DictionaryMudLocalizer()
    {
        _localization = new()
        {
            { "MudDataGrid.IsEmpty", "ist leer" },
            { "MudDataGrid.IsNotEmpty", "ist nicht leer" },
            { "MudDataGrid.Contains", "enthält" },
            { "MudDataGrid.NotContains", "enthält nicht" },
        };
    }
    
    public override LocalizedString this[string key]
    {
        get
        {
            var currentCulture = Thread.CurrentThread.CurrentUICulture.Parent.TwoLetterISOLanguageName;
            if (currentCulture.Equals("de", StringComparison.InvariantCultureIgnoreCase)
                && _localization.TryGetValue(key, out var res))
            {
                return new(key, res);
            }
            else
            {
                return new(key, key, true);
            }
        }
    }
}
Translation Keys

The current default English language localization strings:

Translation Key
English Translation
MudAlert_Close Close Alert
MudBaseDatePicker_NextMonth Next month {0}
MudBaseDatePicker_NextYear Next year {0}
MudBaseDatePicker_PrevMonth Previous month {0}
MudBaseDatePicker_PrevYear Previous year {0}
MudCarousel_Index Index {0}
MudCarousel_Next Next
MudCarousel_Previous Previous
MudChip_Close Close Chip
MudColorPicker_AlphaSlider Alpha Slider
MudColorPicker_Close Close Picker
MudColorPicker_ColorDot Select Color Dot
MudColorPicker_GridView Switch to Grid View
MudColorPicker_HueSlider Hue Slider
MudColorPicker_ModeSwitch Switch Mode
MudColorPicker_PaletteColor Select Palette Color
MudColorPicker_PaletteView Switch to Palette View
MudColorPicker_SpectrumView Switch to Spectrum View
MudColorPicker_ToggleCurrentColor Toggle Current Color
MudDataGrid_AddFilter Add Filter
MudDataGrid_Apply Apply
MudDataGrid_Cancel Cancel
MudDataGrid_Clear Clear
MudDataGrid_CollapseAllGroups Collapse All Groups
MudDataGrid_Column Column
MudDataGrid_Columns Columns
MudDataGrid_Contains contains
MudDataGrid_EndsWith ends with
MudDataGrid_Equals equals
MudDataGrid_EqualSign =
MudDataGrid_ExpandAllGroups Expand All Groups
MudDataGrid_False false
MudDataGrid_Filter Filter
MudDataGrid_FilterValue Filter value
MudDataGrid_GreaterThanOrEqualSign >=
MudDataGrid_GreaterThanSign >
MudDataGrid_Group Group
MudDataGrid_Hide Hide
MudDataGrid_HideAll Hide All
MudDataGrid_Is is
MudDataGrid_IsAfter is after
MudDataGrid_IsBefore is before
MudDataGrid_IsEmpty is empty
MudDataGrid_IsNot is not
MudDataGrid_IsNotEmpty is not empty
MudDataGrid_IsOnOrAfter is on or after
MudDataGrid_IsOnOrBefore is on or before
MudDataGrid_LessThanOrEqualSign <=
MudDataGrid_LessThanSign <
MudDataGrid_Loading Loading...
MudDataGrid_MoveDown Move Down
MudDataGrid_MoveUp Move Up
MudDataGrid_NotContains not contains
MudDataGrid_NotEquals not equals
MudDataGrid_NotEqualSign !=
MudDataGrid_Operator Operator
MudDataGrid_RefreshData Refresh Data
MudDataGrid_Save Save
MudDataGrid_ShowAll Show All
MudDataGrid_Sort Sort
MudDataGrid_StartsWith starts with
MudDataGrid_True true
MudDataGrid_Ungroup Ungroup
MudDataGrid_Unsort Unsort
MudDataGrid_Value Value
MudDialog_Close Close dialog
MudInput_Clear Clear
MudInput_Decrement Decrement
MudInput_Increment Increment
MudNavGroup_ToggleExpand Toggle {0}
MudPageContentNavigation_NavMenu Table of Contents
MudPagination_CurrentPage Current page {0}
MudPagination_FirstPage First page
MudPagination_LastPage Last page
MudPagination_NextPage Next page
MudPagination_PageIndex Page {0}
MudPagination_PreviousPage Previous page
MudRatingItem_Label {0} Rating
MudSnackbar_Close Close snackbar
MudTablePager_FirstPage First page
MudTablePager_LastPage Last page
MudTablePager_NextPage Next page
MudTablePager_PreviousPage Previous page

Customize Translation Interceptor

ILocalizationInterceptor can be used to fully customize the translations. For example if you don't need the default English translation, or you want to get the translation from other source.

using Microsoft.Extensions.DependencyInjection;
using MudBlazor;

builder.Services.AddLocalizationInterceptor<CustomLocalizationInterceptorImpl>();
An unhandled error has occurred. Reload 🗙