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.
Crowdsourced Translations
You can help us translate MudBlazor into your language by contributing to our
Weblate Project.
Visit the Translations Repository for more information.
The crowdsourced translations are provided via the separate NuGet package MudBlazor.Translations
.
Open a terminal and install it with this command.
dotnet add package MudBlazor.Translations
Add the following in Program.cs
to register the crowdsourced translations.
using MudBlazor.Translations; builder.Services.AddMudTranslations();
Custom Localizer Registration
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>();
Custom ResX Localizer 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]; public override LocalizedString this[string key, params object[] arguments] => _localization[key, arguments]; }
Custom Dictionary Localizer 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); } } } }
Custom Translation Interceptor
The interface 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>();
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 |
MudDataGridPager_AllItems | All |
MudDataGridPager_InfoFormat | {0}-{1} of {2} |
MudDataGridPager_RowsPerPage | Rows per page: |
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 |
MudStepper_Complete | Complete |
MudStepper_Next | Next |
MudStepper_Previous | Previous |
MudStepper_Reset | Reset |
MudStepper_Skip | Skip |
MudTablePager_FirstPage | First page |
MudTablePager_LastPage | Last page |
MudTablePager_NextPage | Next page |
MudTablePager_PreviousPage | Previous page |