Search code examples
jqueryasp.net-mvc-3globalization

ASP .NET MVC 3: Modifying validation scripts and Globalizing messages


I'm here now because of two things.

First:

I need to modify a jQuery script to fix that decimal separator (dot or coma). In my country (Argentina), we use the coma as the decimal separator, and jQuery.validation uses the dot. I managed myself to change the RegEx and is now fixed, but my question come from other side.

Whenever I add a View, it references two scripts

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

Since I've modified directly the jquery.validate.js only, how can I refactorize this into the min (I don't know the differences between them, so a little bit of water at this point would be great). ¿It would be better to extend the script? ¿How? (Tried this LenardG's jQuery validate and the comma decimal separator (MVC) but didn't work :( )

I also don't know if I can change one by another just like that and it will keep working.

Second:

I need to globalize the messages from the jQuery client validation.

For example, when you type a letter in a numeric field (lets say age) it displays a message saying "The field age must be a number."... I've been driving myself crazy looking up the entire solution, over and over for that message (IMHO, work of the devil). But obviously, didn't succeed.

Although the good practices would be selecting the culture and that stuff according to the web browser culture, the web application that I have to do has to let the user of the system be the one who selects the culture (maybe in login page or in a user configuration page, but this doesn't matter).

So, if the user selects the es-AR culture (spanish from Argentina), the message that I wanna show is "El campo edad debe ser un número."; if the user selects the fr-FR culture, the message to show should be (thanks Google translate) "Le champ âge doit être un nombre."


Sorry about my english, I hope you can understand my "questions". Thanks people ;)


Solution

  • I'm coding a contrib project for MVC3 which includes an easier way to handle localization of messages: http://blog.gauffin.org/2011/09/easy-model-and-validation-localization-in-asp-net-mvc3/