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.
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?
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!
Member
2 Points
6 Posts
Localize Compare Attribute
Nov 19, 2013 01:48 PM|steveosmith|LINK
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.
Here's the localized string (in English) for FieldMismatch:
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:
Notice, NewPassword is showing the property name, not the localized Display Name. Any thoughts how I can display the localized Display Name?
attribute localize mvc Property
None
0 Points
4 Posts
Re: Localize Compare Attribute
Nov 19, 2013 10:27 PM|VIvian Marie|LINK
http://www.hanselman.com/blog/GlobalizationInternationalizationAndLocalizationInASPNETMVC3JavaScriptAndJQueryPart1.aspx
attribute localize mvc Property
Member
2 Points
6 Posts
Re: Localize Compare Attribute
Nov 20, 2013 05:29 PM|steveosmith|LINK
I don't follow. How does this help me to localize the first parameter for Compare?
attribute localize mvc Property
All-Star
35149 Points
9075 Posts
Re: Localize Compare Attribute
Nov 20, 2013 06:04 PM|smirnov|LINK
Try
Why not simply use a clear text message without {0} and {1}?
attribute localize mvc Property
Member
2 Points
6 Posts
Re: Localize Compare Attribute
Nov 21, 2013 05:43 PM|steveosmith|LINK
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!
attribute localize mvc Property