Integrating with validation

If you add internationalization to an application that uses aurelia-validation, you'll want to translate the error messages. This section explains how to integrate both libraries together to achieve that.

Overriding ValidationMessageProvider

The validation library uses a ValidationMessageProvider class to retrieve error messages. Let's extend this class and use I18N to get messages from a translation file:

src/validation/i18n-validation-message-provider.js

import {inject} from 'aurelia-framework'; import {I18N} from 'aurelia-i18n'; import {ValidationParser, ValidationMessageProvider} from 'aurelia-validation'; @inject(ValidationParser, I18N) export class I18nValidationMessageProvider extends ValidationMessageProvider { ...

Get Learning Aurelia now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.