lib/mongoid/fields/localized.rb in mongoid-8.0.2 vs lib/mongoid/fields/localized.rb in mongoid-8.0.3

- old
+ new

@@ -12,11 +12,13 @@ # # @param [ Hash ] object The hash of translations. # # @return [ Object ] The value for the current locale. def demongoize(object) - if object + return if object.nil? + case object + when Hash type.demongoize(lookup(object)) end end # Is the field localized or not? @@ -74,10 +76,13 @@ elsif object.key?(locale) object[locale] end return value unless value.nil? if fallbacks? && ::I18n.respond_to?(:fallbacks) - object[::I18n.fallbacks[locale].map(&:to_s).find{ |loc| object.has_key?(loc) }] + fallback_key = ::I18n.fallbacks[locale].find do |loc| + object.key?(loc.to_s) || object.key?(loc) + end + object[fallback_key.to_s] || object[fallback_key] end end end end end