views:

493

answers:

2

I'm trying to localize error messages from NHibernate.Validator. From what I have read, the messages should automaticaly be localized if I set the CurrentCulture/CurrentUICultule ; wich I tried without success. I'm using S#arp Architecture with the default configuration. As I said, the only thnig I changed is the CurrentCulture/CurrentUICultule.

Do I have to create a custom message interpolator for nhibernate validator?

A: 

Changing the culture for was not a good idea, since all my website is in spanish, so the path that I took was to create a SpanishMessageInterpolator and then set it up in my nhv.config like:

<property name="message_interpolator_class">NHibernateValidator.SpanishMessageInterpolator, Assembly</property>

And finally I did modify my global.asax.cs file to include the nhv.config file on NHibernate initialization, like:

NHibernateSession.Init(
                webSessionStorage,
                new string[] { Server.MapPath("~/bin/Assembly.dll") },
                new AutoPersistenceModelGenerator().Generate(),
                Server.MapPath("~/NHibernate.config"), Server.MapPath("~/nhv.config"));
A: 

I have posted in my blog about creating a Custom Interpolator that overrides the default messages if they exist in your resources. It allows you to override the default messages and add new messages for your validators. Check it out: NHibernate Validator Custom Messages

Marc Climent