aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel
diff options
context:
space:
mode:
authorHugo Vacher <hugo.vacher@shopify.com>2019-02-27 09:42:02 -0500
committerHugo Vacher <hugo.vacher@shopify.com>2019-03-04 16:54:06 -0500
commit2176f4b30c9f4ea57a0fd4182808976b64202ab0 (patch)
tree407021a9b7315525fc7ec4c1b3fdeb7bb19db7a3 /activemodel
parentd333d85254d27cd572e6ecce8ee850c107a4f340 (diff)
downloadrails-2176f4b30c9f4ea57a0fd4182808976b64202ab0.tar.gz
rails-2176f4b30c9f4ea57a0fd4182808976b64202ab0.tar.bz2
rails-2176f4b30c9f4ea57a0fd4182808976b64202ab0.zip
Fall back to parent locale before it falls back to the :errors namespace
Diffstat (limited to 'activemodel')
-rw-r--r--activemodel/lib/active_model/errors.rb23
1 files changed, 14 insertions, 9 deletions
diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb
index 9fd6f2d89c..d7e682d406 100644
--- a/activemodel/lib/active_model/errors.rb
+++ b/activemodel/lib/active_model/errors.rb
@@ -479,6 +479,14 @@ module ActiveModel
# * <tt>errors.messages.blank</tt>
def generate_message(attribute, type = :invalid, options = {})
type = options.delete(:message) if options[:message].is_a?(Symbol)
+ value = (attribute != :base ? @base.send(:read_attribute_for_validation, attribute) : nil)
+
+ options = {
+ model: @base.model_name.human,
+ attribute: @base.class.human_attribute_name(attribute),
+ value: value,
+ object: @base
+ }.merge!(options)
if @base.class.respond_to?(:i18n_scope)
i18n_scope = @base.class.i18n_scope.to_s
@@ -487,6 +495,11 @@ module ActiveModel
:"#{i18n_scope}.errors.models.#{klass.model_name.i18n_key}.#{type}" ]
end
defaults << :"#{i18n_scope}.errors.messages.#{type}"
+
+ catch(:exception) do
+ translation = I18n.translate(defaults.first, options.merge(default: defaults.drop(1), throw: true))
+ return translation unless translation.nil?
+ end unless options[:message]
else
defaults = []
end
@@ -496,15 +509,7 @@ module ActiveModel
key = defaults.shift
defaults = options.delete(:message) if options[:message]
- value = (attribute != :base ? @base.send(:read_attribute_for_validation, attribute) : nil)
-
- options = {
- default: defaults,
- model: @base.model_name.human,
- attribute: @base.class.human_attribute_name(attribute),
- value: value,
- object: @base
- }.merge!(options)
+ options[:default] = defaults
I18n.translate(key, options)
end