Possiblities for Localization of errorMessage.

Topics: Developer Forum, Project Management Forum, User Forum
Oct 9, 2008 at 9:21 AM
Edited Oct 9, 2008 at 9:43 AM
We have XMLconfiguration files for objects,like Object.validation.xml where we store the rules,that are used.

Sample:
  <property name="Name">      
      <rule errorMessage="Please enter a name."
            typeName="RequiredStringRule"
            ruleSet="default-form"
            />            
    </property>

The thing is that the errorMessage is displayed in the UI to the user.I was wondering of the possibility for localization? We have all the XML files as a dll.But if we were to support multiple languages then how can we achieve the fact that the errorMessage should come say in Arabic or German etc.

One way could be to have different dlls for different languages (this would add additional burden of code somewhere else) but is there any other way? It would be nice if we had something like errorMessageLan=ar-KW or de-DE and a way to add multiple error messages for different languages.Well any feedback would be appreciated.

Thanks in advance.
Oct 9, 2008 at 11:00 AM
There are several ways of achieving this
  1. having different dlls as u mentioned. I agree this this is a little clunky.
  2. loading the validation config from a text file (not embedding them in a dll). and then have some custom code that runs on startup and chooses an xml based on the culture.
    Not a bad solution but it does cause some overhead in keeping validation in sync between files.
  3. using an ErrorMessageProvider. This allows you to defer to creating of the error message to a custom class. the interface u need to implement is
      public interface IErrorMessageProvider
       {
           string RetrieveErrorMessage(Rule rule, object targetObjectValue, object targetMemberValue, object context);
       }
    There is a custom implementation of IErrorMessageProvider included in the framework called KeyedCultureErrorMessageProvider. It uses the error message of a rule as the key to retrieve a culture specific error message from another XML config file. Run the QSWindowsApplicationCSharp project and have a look at MultiLanguageSample.
    With a little work this method could also be used to retrieve error messages from a database.
Now to be honest I have not had to use, or had anyone request, the framework to act in a localized way. So feel free to offer suggestion or criticism on the current implementation.

I will have think on allowing cuture specific error messages to be defined inside the first class xml file. Or if u want to have a go at getting it working feel free to submit a patch.

Regards

Simon
Oct 26, 2008 at 11:45 AM
Edited Oct 26, 2008 at 11:51 AM
Thank you very much for your reply.

It would be great if you could include the validation localization also in the XML file (For example. Employee.validation.xml ).This would reduce much of the work needed to integrate the localization otherwise as mentioned above.

I had gone through the third point you had mentioned, I was thinking if you could add the same essence and implementation for use via the xml file this would be helpful since it would further reduce the crosscutting concerns, since the localization too is managed by the validation framework,and it would only need to know the cultureinfo.This way the xml file would be the only place where all aspects of it would have to be maintained making it more manageable.