Skip to content

DisplayNameFor doesn't lookup resx file despite IStringLocalizer and IHtmlLocalizer working correctly in the Razor page #45292

Open
@Duke4848

Description

@Duke4848

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I've got my Login.cshtml page

@page
@using Microsoft.AspNetCore.Mvc.Localization
@using Microsoft.Extensions.Localization
@inject IStringLocalizer<LoginModel> localizer
@inject IHtmlLocalizer<LoginModel> htmlLocalizer
@model LoginModel

<h1>@htmlLocalizer["Title"]</h1> TRANSLATES WELL
<h1>@localizer["Title"]</h1> TRANSLATES WELL
[...]
div class="checkbox">
   <label asp-for="Input.RememberMe" class="form-label">
        <input class="form-check-input" asp-for="Input.RememberMe" />
        @Html.DisplayNameFor(m => m.Input.RememberMe) //DOESN'T WORK, DOESN'T LOOKUP RESX FILE
    </label>
</div>

In the scaffolded Login.cshtml.cs page model there is an attribute [Display] fr the RememberMe property, but this one is not getting translated despite translation being put in the same resource file

        /// <summary>
        ///     This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used
        ///     directly from your code. This API may change or be removed in future releases.
        /// </summary>
        [Display(Name = "Remember")] //DOESN'T WORK, DOESN'T LOOKUP RESX FILE
        public bool RememberMe { get; set; }

We can see that the structure is correct

enter image description here

Resx file itself:

enter image description here

This is what gets rendered:

enter image description here

Expected Behavior

Remember gets translated according to the contents of the resource file.

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

6.0.402

Anything else?

ASP.NET Core 6

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions