How to localize/customize autogenerated validation error messages?

Last post 05-22-2009 1:54 AM by davidebb. 10 replies.

Sort Posts:

  • How to localize/customize autogenerated validation error messages?

    05-20-2009, 12:03 PM
    • Member
      2 point Member
    • FTeR
    • Member since 08-28-2007, 11:47 AM
    • Posts 17

    How can I localize or customize autogenerated validation error messages in DynamicData without setting validation attributes for every column (and possible error) in MetaData?
    So, insted of "The field <FieldNameHere> must be a valid Integer.", I would like to see "Kérem csak számot adjon meg a <FieldNameHere> mezőben." (which is "Please insert only numbers for <FNH> field.") for every Integer column.

    Column DisplayNames are already localized so it's kinda funny when it says: "The Műcím field is required." (where Műcím is Title).

    Thank You for helping!

  • Re: How to localize/customize autogenerated validation error messages?

    05-20-2009, 2:43 PM
    • Contributor
      5,970 point Contributor
    • ricka6
    • Member since 06-25-2008, 10:04 PM
    • Redmond
    • Posts 956
    • AspNetTeam
      Moderator

    This is a localizable string inside Dynamic Data.  If you run the Hungarian version of the framework, that string should be localized.

    Rick -ASP.Net UE MVC FAQ   Rick on MVC & Dynamic Data   
  • Re: How to localize/customize autogenerated validation error messages?

    05-20-2009, 4:25 PM
    • Member
      2 point Member
    • FTeR
    • Member since 08-28-2007, 11:47 AM
    • Posts 17

    Unfortunately I can't replace the .Net framework on the server. Anyway, I don't like the localized version because it's hard to search for the compiler's error messages.
    What about customization or if I have a globalized app?
    I'm using the 4.0 Preview 4, can it help?

    You know hungarian? : )

  • Re: How to localize/customize autogenerated validation error messages?

    05-20-2009, 5:32 PM
    • Star
      12,384 point Star
    • sjnaughton
    • Member since 04-29-2008, 5:11 PM
    • Newton-le-Willows, Merseyside, UK
    • Posts 2,575
    • TrustedFriends-MVPs

    ricka6:
    If you run the Hungarian version of the framework, that string should be localized.

    Hi Rick, I though with web if the user was using a Hungarian or French browser there should be a way of having the validation error messages appear in there own language (parden me if I completely miss it I18N is relativly new to me), I've been trying to help FTeR via my blog but I was getting nowhere so I  pointed him here Big Smile

    Steve Big Smile

    Always seeking an elegant solution.
    [Oh! If olny I colud tpye!]
    c# Bits blog
    Oh, and don't forget to mark as answer any posts that help you Big Smile
  • Re: How to localize/customize autogenerated validation error messages?

    05-20-2009, 6:01 PM
    • Contributor
      5,970 point Contributor
    • ricka6
    • Member since 06-25-2008, 10:04 PM
    • Redmond
    • Posts 956
    • AspNetTeam
      Moderator

    >>You know hungarian? : )

    That was actually David Ebbo's response when I sent him the question. I guess he must know some.

    Steve is right, the client side error messages will be localized by the client user agent (IE, FF, Chrome, etc).

    Rick -ASP.Net UE MVC FAQ   Rick on MVC & Dynamic Data   
  • Re: How to localize/customize autogenerated validation error messages?

    05-20-2009, 6:24 PM
    • Member
      2 point Member
    • FTeR
    • Member since 08-28-2007, 11:47 AM
    • Posts 17

    The browser's preffered language is set to Hungarian (prtscr). I also set EnableScriptGlobalization="True" and EnableScriptLocalization="True", for the script manager.
    Maybe I'm still missing something.

  • Re: How to localize/customize autogenerated validation error messages?

    05-20-2009, 7:00 PM
    • Contributor
      5,970 point Contributor
    • ricka6
    • Member since 06-25-2008, 10:04 PM
    • Redmond
    • Posts 956
    • AspNetTeam
      Moderator

    David states this should work in the released version - but the preview is not localized. You'll always get English in the previews. Sorry about that - resource constraints.

    Rick -ASP.Net UE MVC FAQ   Rick on MVC & Dynamic Data   
  • Re: How to localize/customize autogenerated validation error messages?

    05-20-2009, 7:08 PM
    • Member
      2 point Member
    • FTeR
    • Member since 08-28-2007, 11:47 AM
    • Posts 17

    Is there no way to overwrite some method or property? It would still be quicker then separately set every column.

  • Re: How to localize/customize autogenerated validation error messages?

    05-20-2009, 8:52 PM
    Answer
    • Contributor
      5,829 point Contributor
    • davidebb
    • Member since 06-11-2002, 8:31 AM
    • Redmond, WA
    • Posts 1,164

    One thing you can try is to change the field templates to set the ErrorMessage to what you want on the various validators after the calls to SetUpValidator().

    David

  • Re: How to localize/customize autogenerated validation error messages?

    05-21-2009, 5:09 AM
    • Member
      2 point Member
    • FTeR
    • Member since 08-28-2007, 11:47 AM
    • Posts 17

    That is a good idea! Thank You!

    If You don't mind my curiosity, how do you recognized Hungarian? It's not a widely spoken language.

  • Re: How to localize/customize autogenerated validation error messages?

    05-22-2009, 1:54 AM
    • Contributor
      5,829 point Contributor
    • davidebb
    • Member since 06-11-2002, 8:31 AM
    • Redmond, WA
    • Posts 1,164

    Well, to be honest, I wasn't 100% sure it was Hungarian, so it was a partial guess. Maybe the 'sz' sequence felt Hungarian :)

    David

Page 1 of 1 (11 items)