Localized Message.

Mar 14, 2013 at 10:35 PM
Thank you for your work, this is amazing.

I have a question about localized message, maybe you can help me.
In documentation I found how localize message with MessageKey

Check(p => p.FirstName).Required().And.IsAlpha().With( m => m.MessageKey = "MissingFirstName!");

My question: From what Resource file we get value by key "MissingFirstName". I need use custom Resource file for localize messages. How or Where I can change name of Resource file.

Thank you for feedback!
Mar 17, 2013 at 3:27 PM

To create new Resource file to add custom messages to, follow these steps:
  1. Create a new Resource File in your project.
  2. Register that resource file with SpecExpress when you configure the catalog:
ValidationCatalog.Configure(x => x.AddMessageStore(new ResourceMessageStore(TestRuleErrorMessages.ResourceManager), "OverrideMessages"));
  1. Use the new MessageKey as you did above, using the name of the resource.
c.Check(x => x.LastName).Required().IsAlpha().With(m => m.MessageKey = "TestRule");
Finally, if you are localizing all the messages it might be easier to follow the Localization instructions at [http://specexpress.codeplex.com/wikipage?title=Localization&referringTitle=Documentation]. Then you won't have to specific the new message key for the built in rules. Also if you need to reuse the same custom rule, when you create it you can specify the MessageKey in the custom rule. The goal is to not repeat yourself!

If you go the localization route, we'd love a copy of your translation so we can include it in the next build for everyone to use.