NHibernate Validation Localization with S#arp Arch

2019-07-20 17:45发布

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?

2条回答
\"骚年 ilove
2楼-- · 2019-07-20 18:35

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"));
查看更多
Lonely孤独者°
3楼-- · 2019-07-20 18:43

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

查看更多
登录 后发表回答