dotnet / dotnet/aspnetcore

DisplayName component does not support IStringLocalizer

Open
#67,070 1 comment 1 reaction 1 assignee Claimed by @oroztocil View on GitHub
area-blazor
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

MVC's `Html.DisplayNameFor` supports automatic localization of the display name via `IStringLocalizer`, enabled by:

```csharp
builder.Services.AddControllersWithViews()
.AddDataAnnotationsLocalization();
```

Blazor's `DisplayName` component does not support this way of localization - only the static resource method with `[Display(ResourceType = typeof(...), Name = "...")]`.

Apart from being a feature gap, it creates disparity in how display names are rendered in Blazor when validation localization is enabled by:

```csharp
builder.Services.AddValidation();
builder.Services.AddLocalizaton();
```

Display names included in form validation error messages are localized via `IStringLocalizer`, while those rendered with `` are not.

We may consider this out-of-scope and ask users to use `IStringLocalizer` (or similar service) directly in the markup instead of the `DisplayName` component, if they need localization.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.