-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Set :en as fallback locale for grape errors when translations are missin... #444
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ class Base < StandardError | |
|
||
BASE_MESSAGES_KEY = 'grape.errors.messages' | ||
BASE_ATTRIBUTES_KEY = 'grape.errors.attributes' | ||
FALLBACK_LOCALE = :en | ||
|
||
attr_reader :status, :message, :headers | ||
|
||
|
@@ -58,7 +59,8 @@ def translate_message(key, options = {}) | |
end | ||
|
||
def translate(key, options = {}) | ||
::I18n.translate(key, options) | ||
message = ::I18n.translate(key, options) | ||
message.present? ? message : ::I18n.translate(key, options.merge({:locale => FALLBACK_LOCALE})) | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should write this in a more concise way: ::I18n.translate(key, options) || ::I18n.translate(key, options.merge({ ... })) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When the locale is missing, an empty string is returned which does not evaluate to false, so the test doesn't pass with this change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're totally right. |
||
|
||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this link relative, without the whole
https://...
thing, it will just work.