lib/grape/exceptions/base.rb in grape-0.5.0 vs lib/grape/exceptions/base.rb in grape-0.6.0
- old
+ new
@@ -2,10 +2,11 @@
module Exceptions
class Base < StandardError
BASE_MESSAGES_KEY = 'grape.errors.messages'
BASE_ATTRIBUTES_KEY = 'grape.errors.attributes'
+ FALLBACK_LOCALE = :en
attr_reader :status, :message, :headers
def initialize(args = {})
@status = args[:status] || nil
@@ -52,14 +53,15 @@
def translate_attribute(key, options = {})
translate("#{BASE_ATTRIBUTES_KEY}.#{key}", { :default => key }.merge(options))
end
def translate_message(key, options = {})
- translate("#{BASE_MESSAGES_KEY}.#{key}", {:default => '' }.merge(options))
+ translate("#{BASE_MESSAGES_KEY}.#{key}", { :default => '' }.merge(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
end
end
end