Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translation breaks with htmlSafe flag #49

Open
hanssen opened this issue Jan 25, 2019 · 3 comments
Open

Translation breaks with htmlSafe flag #49

hanssen opened this issue Jan 25, 2019 · 3 comments

Comments

@hanssen
Copy link

hanssen commented Jan 25, 2019

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
Copy link

ludalex commented Jan 25, 2019

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
Copy link
Author

hanssen commented Jan 25, 2019

@ludalex approach worked fine for me, too.

@jasonmit
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants