Arrrr Arrrr - 4 days ago 4
ASP.NET (C#) Question

Supporting multiple languages for model metadata

In ASP.Net and particularly ASP.Net Core, is there any way to implement multi-language meta-data for models? For instance, given the following:

public class _Person{
[Required]
[Display(Name = "First Name")] // If English
[Display(Name = "Prenom")] // If French
public String FirstName {get; set}
}


and providing error message according to the language if no value is provided for that property in a form, or the max string length exceeds the allowed size.

Answer

You should create multiple .resx files for each language you want to support. You can then link the resx file via:

[Display(Name = "FirstName", ResourceType = typeof(NameOfRescourceFile))]

The resource file would look like this

If you want to know how to create these .resx files take a look at this link