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]; }