2

Beside the annotation-based validation mechanism EF provides the so-called "Facets". Meaning on a string property you could have a "Max Length" Facet (through the EF model configuration) where you specify a max-length of 80 chars. Most often this is done automatically by EF when you use a database first approach.

If now the property contains more than the specified number of chars, EF will throw a DbEntityValidationResult with the message

[PropName]: The field [PropName] must be a string or array type with a maximum length of '80'.

My question: How can I localize such message??? I'd need it in german and italian as well...

Juri
  • 32,424
  • 20
  • 102
  • 136

1 Answers1

1

Maarten Balliauw wrote a blog blog about it:

Localize ASP.NET MVC 2 DataAnnotations validation messages

Update your classes to use the ErrorMessageResourceType and ErrorMessageResourceName parameters instead of the ErrorMessage parameter that you normally pass.

Also, you can localize your DisplayNameAttributes; here's a Stackoverflow post which explains how to do it: Localization of DisplayNameAttribute

Update

I think if you install the .NET Framework Language Pack these standard messages should be translated for you.

A caveat (happened to me): ASP.NET MVC 3 localized validation messages work on my machine, but not on server

Community
  • 1
  • 1
splattne
  • 102,760
  • 52
  • 202
  • 249
  • I'd prefer not to decorate all my entities with validation annotations just for the purpose of localizing the validation msgs. But I thought about the language packs as well before...Guess I have to give it a try – Juri Oct 15 '12 at 10:35