Jan 11, 2011 at 11:38 PM
Edited Jan 12, 2011 at 11:12 AM
Changing the Templates of validators isn't possible and would be a bad idea, because validators can be cached and used across threads and you will end up with race conditions in multi-threaded applications (this would result in showing German error messages
to your English users for instance).
What might work for you is having a validation configuration file per language and switch at runtime between the configurations. Down side is that you have duplicate validation configuration, but it might do the trick for you.
You can create an implementation of IConfigurationSource that determines dynamically which configuration to return. Such a class could look like this:
public class MultiLanguageConfigurationSource
public ConfigurationSection GetSection(string sectionName)
string culture = CultureInfo.CurrentCulture.Name;
var source = new FileConfigurationSource(
"validation." + culture + ".config");
#region IConfigurationSource Members
// Rest of the IConfigurationSource members left out.
// Just implement them by throwing an exception from
// their bodies; they are not used.
You can register this type in the enterprise library configuration or create an instance and supply it to the ValidationFactory as follows:
var validator = ValidationFactory.CreateValidator(typeToValidate,
string.Empty, new MultiLanguageConfigurationSource());