Validatious 2.0

Easy form validation with unobtrusive JavaScript

Multilingual messages

If your site's language is not english, you probably don't want error messages in english. There are several ways of changing languages:

Override messages per field

By overriding messages through the title attribute (HTML extension), you can add messages in any language you like. This is likely not an attractive option for sites with large or many forms.

Pre-translated distribution

Validatious.org offers some other languages than english - you can download a pre-translated version of Validatious if you only need one language.

Language files

When in need of several languages, you can download separate language files which contain only the messages. These can be imported after the Validatious core, and will override the default messages.


Add your own language files

If Validatious doesn't come with a language file for your language, you can easily create your own. In the language file you can override messages for the validators you need (ie you don't need to translate all of them if you're not using all of them). Please consider contributing your translation in exchange for internet fame if you go for this option.

Of course, creating a language file is good also if you just want other defaults than what Validatious offers.

The following example shows how the english language file may look. Note how only a few messages are overridden.

/**
 * English default error messages
 */
v2.$msg({
  'min-length': '${field} should be atleast ${min} characters long',
  'max-length': '${field} should be no more than ${max} characters long',
  'min-val': '${field} should be atleast ${min}',
  'max-val': '${field} should be no bigger than ${min}',
  'email': '${field} should be a valid email address'
});

Of course, this may be done inside an inline script block as well. The ${...} statements work like interpolated variables. The field variable is always available, and will be substituted with the field name. Other available variables are determined by the validator. Refer to the validator reference for a description of available parameters for each validator.

Next: Configuring Validatious | Back to Core API features index

© 2008 Christian Johansen. Validatious is licensed with a BSD License, documentation and site content with CC Attribution-Share Alike. About.