ember-intl / cp-validations

ember-intl support for ember-cp-validations
MIT License
10 stars 13 forks source link

Translation breaks with htmlSafe flag #49

Open hanssen opened 5 years ago

hanssen commented 5 years ago

I just added the htmlSafe flag by default as mentioned here. Then some of my validation message are broken: "undefined is invalid". It seemd the default messages like blank are broken, whereas custom messages still work.

A workaround for me is disabling the htmlSafe flag for the validation messages, which I configured to have prefix: 'forms.errors'.

return this._super(key, assign({ htmlSafe: !key.includes('forms.errors.') }, options));
ludalex commented 5 years ago

Experiencing the same, this is how I managed to get it working:

app/validators/messages.js

import ValidatorsMessages from 'ember-intl-cp-validations/validators/messages';
import { assign } from '@ember/polyfills';

export default ValidatorsMessages.extend({
  getMessageFor(type, options = {}) {
    return this._super(type, assign({ htmlSafe: false }, options));
  }
});

app/services/intl.js here we perform the suggested override to apply htmlSafe to every translation

.....
  // Overrides
  t(key, options) {
    return this._super(key, assign({ htmlSafe: true }, options));
  }
.....
hanssen commented 5 years ago

@ludalex approach worked fine for me, too.

jasonmit commented 5 years ago

If anyone wants to submit a PR, I'd happily review and merge.