locked
Localize Compare Attribute RRS feed

  • Question

  • User1062723977 posted

    I'm localizing some property attributes in my MVC C# view models, but can't figure out how to fully localize the Compare atrribute. As you can see from the code below, I've localized the error message. 

    [Compare("NewPassword", ErrorMessageResourceName = "FieldMismatch", ErrorMessageResourceType = typeof(Resources.Culture.Home.Global))]

    Here's the localized string (in English) for FieldMismatch:

    The {0} field and {1} field don't match.

    the {1} parameter maps to the field named "NewPassword" - the first parameter in the Compare attribute. That field's Display Name gets localized (in English) to New Password. (With a space in it.) However, the warning in my MVC app says the following:

    The Confirm Password field and NewPassword field don't match.

    Notice, NewPassword is showing the property name, not the localized Display Name. Any thoughts how I can display the localized Display Name?


    Tuesday, November 19, 2013 1:48 PM

Answers

  • User1508394307 posted

    Try

    The {0} field and {2} field don't match.

    Why not simply use a clear text message without {0} and {1}?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 20, 2013 6:04 PM

All replies

  • User1062723977 posted

    I don't follow. How does this help me to localize the first parameter for Compare?

    Wednesday, November 20, 2013 5:29 PM
  • User1508394307 posted

    Try

    The {0} field and {2} field don't match.

    Why not simply use a clear text message without {0} and {1}?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 20, 2013 6:04 PM
  • User1062723977 posted

    Thanks, Smirnov, for the input. I tried the {2} fix and got a message the index must be less than the size of the argument list. I was just hoping to keep everything more generic, in case I had two other fields to compare later on. Seems to me if I can localize everything else, there must be a way to localize that parameter. Oh well. I've wated way too much time on this already. I guess I'll have to use your suggestion to implement a clear text message. Thanks again!

    Thursday, November 21, 2013 5:43 PM