According to the documentation:
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.
I'm looking for a way to localize text in DisplayAttribute. Any suggestions to do it in a proper way(s)?
Globalization is the process of designing the application in such a way that it can be used by users from across the globe (multiple cultures). Localization, on the other hand, is the process of customization to make our application behave as per the current culture and locale.
<asp:Localize> is used to specify a Resource defined item, which forces the IDE to display some specified text, and still allows it to resolve at runtime, to the language of the website. This may be useful for the development of a site where the content of the site is actually in a different language.
You can set the ResourceType
on the DisplayAttribute
which can be used to localize your text.
Add a resource .resx
file to your project e.g. MyResources.resx
, and add a resource for your field:
Then reference the name of the field and the MyResources
type in your DisplayAttribute
[Display(Name = "RememberMe", ResourceType = typeof(MyResources))]
public bool RememberMe { get; set; }
The localized resource will be pulled through automatically (see the text box)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With