Scenario
A .NET/WPF desktop application should be localized (or in MS terms globalized) to a different language than English. That is, the UI needs to be adopted completely (labels, icons, ...).
Log file entries, audit trail entries, and other outputs of the application, however, should remain in English to allow the English-speaking service/support personnel reviewing it. They do not speak French or Chinese.
The application relies on RESX files for accomplishing the localization.
The Enterprise Library Validation Block is used for the validation of business rules on the object model.
Now suppose there is a service that validates its given object model arguments prior to executing the real business logic. Under some circumstances it receives invalid object model arguments but continues the execution with best effort. The provision of invalid object model data, however, should be logged in the audit trail and in the log file.
Example of a service using the validation block.
public class Service : IService
{
public void MyMethod(MyObjectModelObject obj)
{
Validator validator = ValidationFactory.CreateValidator(typeof(MyObjectModelObject));
ValidationResults results = validator.Validate(this);
// !!! The messages in the validation results are now already localized to CurrentCulture.
// ... build a log message: msg
if (results.Count > 0)
{
Logger.Log(msg);
}
}
}
As stated in the code comment, when you've called Validate() on the EnterpriseLibrary validator, the validation messages are already localized to French and you have no chance to write them to a e.g. English log file.
In other areas of our application we use a message class that encapsulates the resource id and parameters until we are certain which culture we want to use the resolve the actual string value. You could call it a deferred resource resolution.
Any ideas how to introduce a similar mechanism to the Enterprise Library Validation block? Ideas so far:
- Switching the CurrentCulture temporarily (I don't like that and it solves only half the problem)
- Patch the Enterprise Library Validation Block (I don't like that, too)
Thanks for your help and shared ideas!