NHibernate Validation Localization with S#arp Architecture

二次信任 提交于 2019-12-12 18:55:46

问题


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?


回答1:


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




回答2:


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"));


来源:https://stackoverflow.com/questions/1191309/nhibernate-validation-localization-with-sarp-architecture

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!