I'm currently trying to figure out how to localize the error messages generated by MVC. Let me use standard model binding as an example, so I can explain the problem.
Assuming I have a form in which a user enters age. Then the user enters the "top ten" in the form, but instead of receiving the expected error
"Age must be between 18 and 25 years old."
message
"The value ten is not valid for Age."
.
The age property of an object is defined below:
[Range(18, 25, ErrorMessageResourceType = typeof (Errors), ErrorMessageResourceName = "Age", ErrorMessage = "Range_ErrorMessage")] public int Age { get; set; }
After some digging, I notice that this error text comes from System.Web.Mvc.Resources.DefaultModelBinder_ValueInvalid in the MvcResources.resx file.
Now, how to create localized versions of this file?
As a solution, for example, you need to download the MVC source and add MvcResources.en_GB.resx , MvcResources.fr_FR.resx , MvcResources.es_ES.resx and MvcResources.de_DE.resx , and then compile my own version of MVC.dll ?
But I do not like this idea. Does anyone know a better way?
Dai bok
source share