6

I'm trying to localize the validation messages of the data-annotations. I thought that it could be done as described here: Supporting ASP.NET MVC 3 Validation with Non-English Locales.

Now it says that ASP.NET MVC and types in the System.ComponentModel.DataAnnotations namespace use their own localized messages. So is that more or less useless to me and only a help for formatting for example prices?

But back to the real question, so the only way to localize the validation messages is doing something like this? localize default model validation in mvc 2

Just trying to get some clearification here, thanks =)

Community
  • 1
  • 1
Nischo
  • 454
  • 6
  • 20

3 Answers3

3

You could use resource files:

public class UserViewModel
{
    [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(UserResources))]
    [Display(Name = "FirstName", ResourceType = typeof(UserResources))]
    public string FirstName { get; set; }
}

You may checkout the following blog post as well.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • so nothing can be done with jQuery? either you have to figure out the default keys of the messages or specify the text on each property on every single attribute? – Nischo May 16 '11 at 07:39
3

The resources for the data annotations are in the .NET Framework 4. You have to install the language pack for the .NET Framework.

slfan
  • 8,950
  • 115
  • 65
  • 78
  • Watch out for an MVC3 bug. One message can't be localized easily. See this question http://stackoverflow.com/questions/4828297/how-to-change-data-val-number-message-validation-in-mvc-while-it-generate-by-he – Phil Hale Jun 15 '11 at 14:35
0

Just install the the dot net 4 full language pack in the desired language and you will get the localization of the DataAnnotations validation messages.

Michael Sander
  • 2,677
  • 23
  • 29
  • yes, it actually put me on the right way. just confused the post while trying to answer this http://stackoverflow.com/questions/6771968/display-standard-razor-mvc-3-validation-messages-displayed-in-another-language/7313350#7313350 – Michael Sander Oct 05 '11 at 11:57