I tried to use a custom interpolator:
...
public class EntityMessageInterpolator : IMessageInterpolator
{
public string Interpolate(string message, IValidator
validator,
IMessageInterpolator defaultInterpolator)
{
return "Hello World!";
}
}
...
...
// NHibernate Validation...
NHVConfiguration nhvConfiguration = new
NHVConfiguration();
nhvConfiguration.Properties.Add(
NHibernate.Validator.Cfg.Environment.ValidatorMode,
"UseAttribute");
nhvConfiguration.Properties.Add
(NHibernate.Validator.Cfg.
Environment.MessageInterpolatorClass,
typeof(EntityMessageInterpolator).
AssemblyQualifiedName);
nhvConfiguration.Mappings.Add(new
MappingConfiguration(GetEntityAssemblyName(),
null));
ValidatorEngine engine = new ValidatorEngine();
engine.Configure(nhvConfiguration);
ValidatorInitializer.Initialize(configuration,
engine);
...
Questions:
1) I was expecting to get the validation message "Hello World!" for
all validations, but I get the default ones. What am I missing?
2) What do you mean by "use our JIRABTW NHV accept custom
ResourceManager"?
3) I want to use different validation messages for the same type of
validation in different entitites. Example: For the Name property in a
Person class with a NotNullNotEmpty constraint I would like to say:
"You need to specify a name for the person...". For the Name property
in a Employee class with a NotNullNotEmpty constraint I would like to
say: "The employee needs a name...". Is this possible with the
ResourceManager approach?
<span style="color:gray;font-size:80%;">Need to know if HTML is
enabled…</span>
On 15 Feb, 22:30, Fabio Maulo <[email protected]> wrote:
> 1) in theory you don't need to do nothing because we are hosting translation
> for various languages; if you have a new one use our JIRABTW NHV accept
> custom ResourceManager... we only need to add a configuration property
>
> 2) an example of a simple custom interpolator is in our tests
> (see PrefixMessageInterpolator). The Message interpolator can be configured
> (is one of the properties of NHV configuration)
>
> 2009/2/15 knut <[email protected]>
>
>
>
>
>
>
>
> > I want to be able to read validation messages from resource files. I
> > think I need to choose one of these solutions:
>
> > "Alternatively you can provide a ResourceManager while checking
> > programmatically the validation rules on a bean or if you want a
> > completly different interpolation mechanism, you can provide an
> > implementation of NHibernate.Validator.Engine.IMessageInterpolator."
> > ---http://nhforge.org/doc/nhv/en/: 3.3. Error messages
>
> > The problem is that I don't know how to do what has been suggested.
>
> > 1) How do I provide a new ResourceManager?
> > 2) How do I provide an implementation of
> > NHibernate.Validator.Engine.IMessageInterpolator
>
> > Best regards!
> > Knut
>
> --
> Fabio Maulo
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---