本地化 MVC Web 应用中的标识错误消息 ASP.NET

Localizing Identity Error Messages in ASP.NET MVC web app

提问人:joeOla 提问时间:9/18/2023 最后编辑:joeOla 更新时间:10/10/2023 访问量:42

问:

我已经本地化了应用程序的一般视图,例如 Index.html 和其他一些页面。当需要本地化身份页面(登录、注册等)时。它没有按预期工作。我在这里尝试了很多建议,但它们似乎对我不起作用

enter image description here

  • 重写 IdentityErrorDescriber
  • 在我的资源文件夹中创建资源文件 - 我在我的资源文件夹中创建了资源文件,并为 en 和 zh 添加了错误消息,并且我已经配置了我的“Program.cs”,因为就像我说的,我已经本地化了一般视图
builder.Services.AddControllersWithViews()
    .AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix);

builder.Services.AddLocalization(options => options.ResourcesPath = "Resources");

builder.Services.Configure<RequestLocalizationOptions>(options =>
{
    var supportedCultures = new[] { new CultureInfo("en-US"), new CultureInfo("zh-Hans") };
    options.DefaultRequestCulture = new RequestCulture("en-US");
    options.SupportedUICultures = supportedCultures;
});

var app = builder.Build();

app.UseRequestLocalization();

这一切都无济于事

在我的“Register.cshtml.cs”中,我尝试使用“RequiredNum”,我已经将其作为密钥保存在 ErrorMessages 资源文件中。

    [DataType(DataType.Text)]
    [Display(Name = "UserName")]
    public string UserName { get; set; }

但是我没有在我的页面上获得键的值,而是在我的页面上得到了“RequiredNum”,如下所示

Instead of errormessage value, I got the Key

我想就如何做到这一点寻求帮助/指导,以便我可以成功本地化身份验证错误消息。任何帮助将不胜感激。

C# asp.net asp.net-mvc 剃刀 asp.net 标识

评论

0赞 Md Farid Uddin Kiron 9/19/2023
"(Login, Register e.t.c)."这两个不起作用还是什么都没有起作用?除此之外,除了错误消息之外,其他本地化内容是否有效?
0赞 joeOla 10/10/2023
@Md Farid Uddin Kiron 除了 Register.cshtml 和 Login.cshtml 上的错误消息外,本地化还适用于其他页面

答: 暂无答案