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

I18n support for all Grape exceptions #306

Closed
niedhui opened this issue Jan 6, 2013 · 9 comments
Closed

I18n support for all Grape exceptions #306

niedhui opened this issue Jan 6, 2013 · 9 comments

Comments

@niedhui
Copy link
Contributor

niedhui commented Jan 6, 2013

eg:
raise Grape::Exceptions::ValidationError, :status => 400, :param => attr_name, :message => "invalid parameter: #{attr_name}"

can invalid parameter be I18n compatible

@dblock
Copy link
Member

dblock commented Jan 6, 2013

There's nothing built-in into Grape for this, but since this is something that happens at runtime, can you just do the translation as you do it for the rest of your strings?

@niedhui
Copy link
Contributor Author

niedhui commented Jan 6, 2013

Hi, I found grape denpends on activesupport, and activesupport depends on I18n, will this be a feature

@dblock
Copy link
Member

dblock commented Jan 6, 2013

If you contribute it, I would definitely take it.

@niedhui
Copy link
Contributor Author

niedhui commented Jan 7, 2013

thanks, I'll try it later

@dblock
Copy link
Member

dblock commented Jan 13, 2013

There're several places where Grape calls raise with message text. We want all exceptions to start inheriting a base class and add i18n support everywhere. Mongoid does a fantastic job at this, which I've reused in the heroku-forward gem: https://github.com/dblock/heroku-forward/tree/master/lib/heroku/forward/errors - I want something like that.

@niedhui
Copy link
Contributor Author

niedhui commented Jan 16, 2013

I had took a vacation these days, and return to work now, I'll do it this week. : )

@niedhui
Copy link
Contributor Author

niedhui commented Jan 22, 2013

Hi, I'm doing the all-exception-i18n work.
Move all translation to Grape::Exceptions::Base, Implment problem/summary/resolution exception message.
and found sometimes ,it's a little verbose to show problem/summary/resolution long exception message,
especially for the validation errors. the validation error message will show for the end user, not api developer, so simple 'the age must be integer' is better for 'problem:xxxx\n summary:yyy\n'.
So Here's what I had done.

grape:
  errors:
     messages:
       missing_vendor_option1:  missing :vendor option.
       missing_vendor_option2:
          problem: 'missing :vendor option.'
          summary: 'when version using header, you must specify :verdor option. '
          resolution: "eg: version 'v1', :using => :header, :vendor => 'twitter'"

the error message for missing_vendor_option1 is just the simple 'missing :vendor option.'
and the error message for missing_vendor_option2 is the verbose one
I had push my code:
niedhui@f6e3d95

Just want to make sure I'm on the right way /

thanks

@dblock
Copy link
Member

dblock commented Jan 22, 2013

Yep, that's on the right track.

@dblock
Copy link
Member

dblock commented Feb 9, 2013

Closing, thanks @niedhui for the implementation.

@dblock dblock closed this as completed Feb 9, 2013
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