Skip to content

Commit

Permalink
doc(ValidationMessageProvider): getDisplayName updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jdanyow committed Dec 4, 2016
1 parent 4120e25 commit aacaef2
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions doc/article/en-US/validation-basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,16 @@ You can override the `ValidationMessageProvider`'s `getMessage(key: string): Exp
</source-code>
</code-listing>

You can also override the `ValidationMessageProvider`'s `getDisplayName(propertyName: string): string` method:
You can also override the `ValidationMessageProvider`'s `getDisplayName(propertyName: string, displayName: string): string` method:

<code-listing heading="Overriding getDisplayName">
<source-code lang="ES 2015">
import {ValidationMessageProvider} from 'aurelia-validation';

ValidationMessageProvider.prototype.getDisplayName = function(propertyName) {
ValidationMessageProvider.prototype.getDisplayName = function(propertyName, displayName) {
if (displayName !== null && displayName !== undefined) {
return displayName;
}
return i18next.t(propertyName);
};
</source-code>
Expand Down Expand Up @@ -764,7 +767,7 @@ In `aurelia-validation` the object and property validation work is handled by th

`aurelia-i18n` is Aurelia's official I18N plugin. Check out the project's [readme](https://github.com/aurelia/i18n/blob/master/README.md) for information on how to use `aurelia-i18n` in your application.

Integrating `aurelia-i18n` with `aurelia-validation` is easy. All standard validation messages are supplied by the `ValidationMessageProvider` class. To translate the messages, override the `getMessage(key)` and `getDisplayName(propertyName)` methods with implementations that use `aurelia-i18n` to fetch translated versions of the messages/property-names.
Integrating `aurelia-i18n` with `aurelia-validation` is easy. All standard validation messages are supplied by the `ValidationMessageProvider` class. To translate the messages, override the `getMessage(key)` and `getDisplayName(propertyName, displayName)` methods with implementations that use `aurelia-i18n` to fetch translated versions of the messages/property-names.

Here's how to override the methods, in your main.js, during application startup:

Expand All @@ -783,7 +786,10 @@ Here's how to override the methods, in your main.js, during application startup:
return this.parser.parseMessage(translation);
};

ValidationMessageProvider.prototype.getDisplayName = function(propertyName) {
ValidationMessageProvider.prototype.getDisplayName = function(propertyName, displayName) {
if (displayName !== null && displayName !== undefined) {
return displayName;
}
return i18n.tr(propertyName);
};

Expand Down

0 comments on commit aacaef2

Please sign in to comment.