This project is read-only.

Localize validation messages for a custom form

Topics: Localization
Oct 24, 2013 at 8:29 PM

Well I first wrongly posted this question as a Issue, that was not very smart...

I just installed Orchard (V1.7.1) for the first time and created a custom form with a text box and a text area. They both have the 'required' checkbox enabled. Now I noticed HTML 5 client side validation is used for the text box but the text area is validated server side.

Now I like to enable client side validation. I found a posting (in 2012) which states you have to add:

<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>

to the web.config and comment out:

ModelValidatorProviders.Providers.Add(new LocalizedModelValidatorProvider());

in a class named 'OrchardStarter'

Now my questions are:
  1. Is the above still true for version 1.7.1?
  2. If yes, where is the OrchardStarter class located?
  3. Can the server side validation messages be translated somehow? It now says something like 'The somefield is mandatory'. I enabled the localisation module and hoped it was translated automatically.
Best regards,

Evert Wiesenekker
Oct 26, 2013 at 9:03 AM
Edited Oct 26, 2013 at 9:04 AM
  1. You don't have to modify the source code anymore, but you do need to either add the two keys to web.config, or enable client side validation per view using code.
  2. You'll find it using the Navigate To feature or Search feature.
  3. Definitely, use PO files to translate strings. This works because Orchard uses the LocalizedModelValidatorProvider, which registers LocalizedRequiredAttribute, LocalizedRangeAttribute, LocalizedStringLengthAttribute and LocalizedRegularExpressionAttribute. So the ErrorMessage properties of these attributes will be localized using T.
Marked as answer by Eefhert on 10/26/2013 at 12:13 PM