ASP.NET Core DisplayAttribute本地化 [英] ASP.NET Core DisplayAttribute Localization

查看:233
本文介绍了ASP.NET Core DisplayAttribute本地化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据文档:

运行时不查找非验证属性的本地化字符串.在上面的代码中,电子邮件"(来自[Display(Name ="Email")])不会被本地化.

The runtime doesn’t look up localized strings for non-validation attributes. In the code above, "Email" (from [Display(Name = "Email")]) will not be localized.

我正在寻找一种在DisplayAttribute中本地化文本的方法.有任何建议以适当方式做到这一点吗?

I'm looking for a way to localize text in DisplayAttribute. Any suggestions to do it in a proper way(s)?

推荐答案

您可以在DisplayAttribute上设置ResourceType,该文本可用于本地化文本.

You can set the ResourceType on the DisplayAttribute which can be used to localize your text.

将资源.resx文件添加到您的项目中,例如MyResources.resx,并为您的字段添加资源:

Add a resource .resx file to your project e.g. MyResources.resx, and add a resource for your field:

然后在DisplayAttribute

[Display(Name = "RememberMe", ResourceType  = typeof(MyResources))]
public bool RememberMe { get; set; }

本地化的资源将被自动提取(请参见文本框)

The localized resource will be pulled through automatically (see the text box)

这篇关于ASP.NET Core DisplayAttribute本地化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆