Home » ASP » ASP.MVC » How to localize property name?

How to localize property name?

If you are using Html Helper to generate your form you may end up with label with the property name into it. You may also have error message with the property name. The problem is if your object contain English term, you would prefer not to show them in English if you write something in French.

public class Person
{
    public string Name { get; set; }
}

The example above could display the word “Name” in a localized string, which is not what we want. But, if we use the Display data annotation attribute, it’s possible to localize the property Name.

public class Person
{
    [Display(ResourceType = typeof(ResourceFileTypeHere), Name="NamePropertyKey")]
    public string Name { get; set; }
}

This will search inside the resource specified the key inside the Name attribute. That’s it, you have your property localized.

If you like my article, think to buy my annual book, professionally edited by a proofreader. directly from me or on Amazon. I also wrote a TypeScript book called Holistic TypeScript

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.