jasonmit / ember-i18n-cp-validations

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

Add conditionals in error messages #20

Closed IAmJulianAcosta closed 8 years ago

IAmJulianAcosta commented 8 years ago

Hi! I'm trying use genders in my translation, like this:

invalid                : "{{description}} es {{#if gender}}inválido{{else}}inválida{{/if}}",

But it seems that is not working. Is this supported?

jasonmit commented 8 years ago

Not that I'm aware of. It is whatever ember-i18n supports since it defers to i18ns compiler.

It might be useful to open up a discussion on ember-i18n around how others implement gender within translations.

The best I can recommend is to pass the dynamic portions as an attribute.

IAmJulianAcosta commented 8 years ago

@jasonmit could you please help me with an example of dynamic portions? I'm just starting with ember-i18n and don't know how to do it.

Thanks!

jasonmit commented 8 years ago

Certainly. I only have access to my phone until Monday so I'll put together an example then. Thanks

IAmJulianAcosta commented 8 years ago

Hi Jason, just a friendly reminder :)

Julián Acosta

El 24 sept. 2016 2:18 PM, "Jason Mitchell" notifications@github.com escribió:

Certainly. I only have access to my phone until Monday so I'll put together an example then. Thanks

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jasonmit/ember-i18n-cp-validations/issues/20#issuecomment-249382435, or mute the thread https://github.com/notifications/unsubscribe-auth/ABwloARo-BoSFv-U-nCYmjFL0aBWnwUAks5qtXdngaJpZM4KFYpf .

jasonmit commented 8 years ago
age: validator('presence', {
  presence: true,
  // this will be invoked everytime the age attr changes
  gender(/* model */) {
    // logic for determining gender here
    return 'dynamic, will be inserted in the gender placeholder';
  }
})
blank: "{{description}} es {{gender}}"

If you want, I'd love if you could update the README in a way that would make sense for others. I haven't had a use for this, but clearly the docs are lacking to make this known.

jasonmit commented 8 years ago

Updated README to reflect this and wrote a test to cover support for passing attributes which should address the underlying concern. The tests in #21 may be more useful than the contrive example I gave above.

Feel free to reopen if you have any other questions.