jasonmit / ember-i18n-cp-validations

ember-i18n support for ember-cp-validations
MIT License
21 stars 16 forks source link

messageKey does not work #18

Closed Reinmar-De-Grasse closed 8 years ago

Reinmar-De-Grasse commented 8 years ago

I have: app/locales/en/translations.js

export default {
  custom_errors: {
    empty_entity_name: "Enter entity name"
  }
};

app/models/entity.js

const Validations = buildValidations({
  name: validator('presence', {presence: true, messageKey: 'custom_errors.empty_entity_name'})
});
export default DS.Model.extend(Validations, {
  name: DS.attr('string')
});

but my messageKey just ignored at getMessageFor: i18n.t(key, options) and errors.blank used

/*
key "errors.blank"
options {description:"This field"
messageKey:"custom_errors.empty_entity_name"
presence:true}
*/
return this.formatMessage(unwrap(i18n.t(key, options))); //"This field can't be blank"
jasonmit commented 8 years ago

Did you specify the prefix as custom_errors as documented here: https://github.com/jasonmit/ember-i18n-cp-validations#customizing-the-prefix

Maybe in the future I'll drop the prefix, but currently that's required if you are namespacing under custom_errors instead of the default errors

Reinmar-De-Grasse commented 8 years ago

With prefix (app/validators/messages.js):

import ValidatorsMessages from 'ember-cp-validations/validators/messages';

export default ValidatorsMessages.extend({
  prefix: 'custom_errors'
});

and:

  name: validator('presence', {presence: true, messageKey: 'custom_errors.empty_entity_name'}),

i got: {description} can't be blank

With prefix and:

  name: validator('presence', {presence: true, messageKey: 'empty_entity_name'}),

i got: {description} can't be blank

I just want custom path to error message for concrete field. May be custom path inside default "errors". How?

jasonmit commented 8 years ago

https://github.com/jasonmit/___i18ncpvalidationsmessagekey/commit/d33d26b102b0d5437ca3c77fd80f9b05072f9ce9

I cannot reproduce this, run the above app and look at what I am doing versus what you have in your project. Reopen if you still have issues and can reproduce it with an example app like the one above.

Reinmar-De-Grasse commented 8 years ago

I think it was an older version of ember-i18n-cp-validations (2.6.0 in your link versus my 2.4.0).

I update all dependencies up to your example and it works now. Thank you!