Skip to content

Commit

Permalink
fix: prefixed intlKey existence
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismllr committed Jun 15, 2020
1 parent bdd19a1 commit 97238fc
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions addon/validators/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,42 @@ export default class ValidationMessages extends DIProvider {
}

getDescription(context) {
const descKey = `${this.prefix}.${context.descriptionKey}`;
const { prefix, intl } = this;
const descKey = `${prefix}.${context.descriptionKey}`;

if (this.intl && this.intl.exists(descKey)) {
return this.intl.t(descKey);
if (intl && intl.exists(descKey)) {
return intl.t(descKey);
}

return context.description || ValidatorsMessages.defaultDescription;
}

getMessageFor(type, context) {
const { prefix } = this;
const { prefix, intl, getDescription } = this;
const messageKey = context.intlKey || type;
const prefixedMessageKey = `${prefix}.${messageKey}`;

const ctx = {
...context,
description: this.getDescription(context)
description: getDescription(context)
};

// if ember-intl addon is not installed, call the validators method
if (!this.intl) {
if (!intl) {
return ValidatorsMessages.getMessageFor(type, ctx);
}

// Otherwise, look it up in intl
if (this.intl.exists(messageKey)) {
return this.intl.t(`${prefix}.${messageKey}`, ctx);
if (intl.exists(prefixedMessageKey)) {
return intl.t(prefixedMessageKey, ctx);
}

warn(
`[validation-state] Internationalized string not provided for <${type}>. Falling back to ember-validators Message builder`,
{ id: 'validation-state.messages.not-defined-intl' }
);

// Fall back to root getMessageFor if user has not defined an intl key for the current type
return ValidatorsMessages.getMessageFor(type, ctx);
}
}

0 comments on commit 97238fc

Please sign in to comment.