小编Dar*_*gan的帖子

Blazor WebAssembly 客户端数据注释本地化

Asp.net core 服务器端本地化有很好的文档记录并且对我有用。但是,如何在 Blazor WebAssembly 客户端上本地化 DTO 模型上的 DataAnnotations?

在服务器端,我添加了下面的代码,并且 DataAnnotations 已本地化。一切都按预期进行。

...
services
.AddRazorPages()              .AddViewLocalization(Microsoft.AspNetCore.Mvc.Razor.LanguageViewLocationExpanderFormat.Suffix)
                .AddDataAnnotationsLocalization(
                    options =>
                    {
                        options.DataAnnotationLocalizerProvider = (type, factory) =>
                        {
                            return factory.Create(typeof(CommonStrings));
                        };

                    });
...
Run Code Online (Sandbox Code Playgroud)

但是我如何在 Blazor 客户端(WebAssembly)上做同样的事情呢?例如,我有一个位于客户端的模型:

public class ApplicationUserDTO
    {
        public string Id { get; set; }

        [Required(ErrorMessage ="Field {0} is required")]
        [Display(Name ="First name")]
        public string FirstName { get; set; }

        [Required]
        [Display(Name = "Last name")]
        public string LastName { get; set; }

        [Required]
        [Display(Name = "Email")]
        public string Email { …
Run Code Online (Sandbox Code Playgroud)

client localization data-annotations webassembly blazor

3
推荐指数
1
解决办法
2965
查看次数