Return to doc.sitecore.com

Valid for Sitecore 5.2, 5.3
Can Validation Error Messages Be Multilingual?

Q:

Can validation error messages be multilingual?

A:

This functionality is not supported by default. However, we came up with the workaround described below.

The following processor defined in the saveUI pipeline is called whenever an item is saved. It contains a single method called Process which validates the field values through the regular expressions defined for them on the template basis.

<processor mode="on" type="Sitecore.Pipelines.Save.ValidateFields, Sitecore.Kernel" />

To replace the default processor definition with a custom one, follow the steps below:

  1. Create a custom class which will contain only the Process method where we will modify the existing code so that it represents the currently selected language of the item.
    Click here to download the code snippet.
  2. Compile it and place it into the bin folder.
  3. Modify the default processor definition to the following one (where CustomValidateFields is the name of the assembly):

    <processor mode="on" type="Custom.Pipelines.Save.ValidateFields, CustomValidateFields" />

Now we need to make some changes to the templates. Let’s assume that we have a template named Contact with the field named ZIP which contains the ZIP code value. Since we have two languages in the system, we need to set different validation error text and the validation expression for each language. In order to achieve this, we need to make the ValidationText field nonshared  between languages. Let’s go to the Standard Template, locate this field and uncheck the Shared checkbox for it (and possibly for the Validation field as well):

/upload/sdn5/faq/api/language validation/validation_error_messages 1.png 

Here is how the Contacts template is configured.

See the English version of the template in the picture below:

/upload/sdn5/faq/api/language validation/validation_error_messages 2.png 

See the Danish version of the template in the picture below:

/upload/sdn5/faq/api/language validation/validation_error_messages 3.png 

Note: We use even different validation expression for the ZIP field in Danish:

As a result, we get different error message boxes for each language:

 /upload/sdn5/faq/api/language validation/validation_error_messages 4.png

 /upload/sdn5/faq/api/language validation/validation_error_messages 5.png