ASP.NET MVC validation message does not get localized
Asked Answered
B

2

12

I am using ASP.NET MVC 4 with unobtrusive clientside validation. The language in my application is german (defined in the web.config file)

If i have a required field (configured with data-annotations in my Code First Classes), the client side validation works fine. the only downside: The Message is not Localized.

The Field XXXX is required.

Is there a solution out for this problem?

Brigand answered 14/8, 2013 at 10:53 Comment(0)
B
17

You must install the .NET Framework Language pack, according to your .NET Framework version:

Microsoft .NET Framework 4.5 Language Pack: http://www.microsoft.com/de-de/download/details.aspx?id=30667

Microsoft .NET Framework 4 Full Language Pack: http://www.microsoft.com/de-de/download/details.aspx?id=23067

In these pages, check the requirements, in order to see if they meets your needs (i.e.: Operating System Version, x86 or x64, etc.). If they don't meet your needs, search on Google something like "Microsoft .NET Framework German Language Pack".

Bolection answered 14/8, 2013 at 12:21 Comment(7)
i've tried the links. my system tells me, that the language pack is already part of the system-installation -> seems that i have it already installed, but the error messages are still in english...Brigand
Do you have, in your Web.config, something like this: <globalization culture="de-DE" uiCulture="de-DE" ..... /> ?Bolection
Try uninstall the language pack you have in your system and then install the new one.Bolection
There is no explicit language pack installed on my system (win 8), and the error message is (translated): `Microsoft .NET 4.5 is already installed' (seems that the LanguagePack is always installed?)Brigand
Maybe this link can help you: social.msdn.microsoft.com/Forums/windowsazure/en-us/…Bolection
The Link from @joe-r helped me finally - there seems to be a problem with the Language Pack in Win 8... Thanks!!Brigand
@FabioS, it would be great if you also mentioned in your answer that the right globalization element needs to be added to the web.config file.Hymnology
S
3

Yes - reference your resource file in your validation attributes:

[Required(ErrorMesageResourceName="LastName", ErrorMessageResourceType=typeof(YourResourceClassName))]
Swathe answered 14/8, 2013 at 10:57 Comment(4)
The downside with annotating the ressourceName is, that you have to do it for EVERY Property, and i have lots of them... (beside from that - there have to be a smarter solution!? because the information is already there when i annotate [Required], only the translation is missing)Brigand
Yes, it is an issue adding resource file references to every property but when you want a different language it's very simple - just drop in another resource file.Swathe
Also, you'll find that relying on the default messages (even in German) is too limited for anything but the most simple website. So even if you get the language pack sorted I'd still go for resource files.Swathe
It seems that there is an issue with Windows 8 and the language pack, this may help - support.microsoft.com/kb/2738065Swathe

© 2022 - 2024 — McMap. All rights reserved.