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

ds-error translations #35

Open
hanssen opened this issue Apr 18, 2017 · 5 comments
Open

ds-error translations #35

hanssen opened this issue Apr 18, 2017 · 5 comments

Comments

@hanssen
Copy link

hanssen commented Apr 18, 2017

Hello,

when the server sends an i18n-key as response, it would be nice if the according translation would appear with a ds-error validation. Currently only the static text is shown. Maybe a flag or separate i18n key in the response would be a good choice, but a lookup of the response text in the translations and fallback to it might be good enough.

Is this already possible with the current implementation? Does my issue sound like a useful new feature?

Many thanks in advance,
Sascha

@jasonmit
Copy link
Owner

@hanssen I don't typically use ember-data so I'm not aware of what you're referring to. Can you provide examples? I also don't want to couple ember-i18n-cp-validations to anything ember-data, so if this solution involves that it's best to treat it as a standalone addon.

@hanssen
Copy link
Author

hanssen commented Apr 21, 2017

@jasonmit I am using following ember-cp-validations validator: validator('ds-error')

The server responds with following message:

errors: [{
  detail: 'forms.errors.already_in_use',
  source: { pointer: 'data/attributes/username' }
}]

The message from detail automatically appears as validation error message in my view.

So ember-data requires this error format and ember-cp-validations handles it very nicely with the according validator. I am only missing the translation.

My idea was to look up the detail message and translate it, if a translation could be found. On the other hand, the detail message might not be intended for i18n usage. So we might extend the errors object by an i18n attribute, which will be used to retrieve the translation.

errors: [{
  i18n: 'forms.errors.already_in_use',
  detail: 'error xyz',
  source: { pointer: 'data/attributes/username' }
}]

@jasonmit
Copy link
Owner

@hanssen sorry for the late response. I would like to land support to address this. Unsure if I'd want to couple it to an i18n prop, any solution should be flexible to handle different shaped error objects.

@hanssen
Copy link
Author

hanssen commented May 31, 2017

@jasonmit I referred to the error object docs and the meta object seems to be a pretty solution:

errors: [{
  source: { pointer: 'data/attributes/username' },
  meta: { messageKey: 'forms.errors.already_in_use' }
}]

@jasonmit
Copy link
Owner

@hanssen I'm on board with that.

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

No branches or pull requests

2 participants