lib/grape/exceptions/base.rb in grape-0.14.0 vs lib/grape/exceptions/base.rb in grape-0.15.0
- old
+ new
@@ -36,19 +36,19 @@
short_message
end
end
def problem(key, attributes)
- translate_message("#{key}.problem", attributes)
+ translate_message("#{key}.problem".to_sym, attributes)
end
def summary(key, attributes)
- translate_message("#{key}.summary", attributes)
+ translate_message("#{key}.summary".to_sym, attributes)
end
def resolution(key, attributes)
- translate_message("#{key}.resolution", attributes)
+ translate_message("#{key}.resolution".to_sym, attributes)
end
def translate_attributes(keys, options = {})
keys.map do |key|
translate("#{BASE_ATTRIBUTES_KEY}.#{key}", options.reverse_merge(default: key))
@@ -58,10 +58,17 @@
def translate_attribute(key, options = {})
translate("#{BASE_ATTRIBUTES_KEY}.#{key}", options.reverse_merge(default: key))
end
def translate_message(key, options = {})
- translate("#{BASE_MESSAGES_KEY}.#{key}", options.reverse_merge(default: ''))
+ case key
+ when Symbol
+ translate("#{BASE_MESSAGES_KEY}.#{key}", options.reverse_merge(default: ''))
+ when Proc
+ key.call
+ else
+ key
+ end
end
def translate(key, options = {})
message = ::I18n.translate(key, options)
message.present? ? message : ::I18n.translate(key, options.merge(locale: FALLBACK_LOCALE))