4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/mongoid/verbalize/verbalized_validator.rb', line 4
def validate_each record, attribute, value
if options[:mode] == :only_default
if record.send("#{attribute}_translations_raw")[::I18n.default_locale.to_s].blank?
record.errors.add(attribute, :locale_blank, options.except(:mode).merge(
:cur_locale => ::I18n.t(:"locales.#{::I18n.default_locale}", :default => ::I18n.default_locale.to_s)
))
end
elsif options[:mode] == :one_locale
record.errors.add(attribute, :all_locales_blank, options.except(:mode)) if record.send("#{attribute}_translations_raw").empty?
elsif options[:mode] == :all_locales
diffloc = ::I18n.available_locales - record.send("#{attribute}_translations_raw").keys.collect { |key| key.to_sym }
diffloc.each do |locale|
record.errors.add(attribute, :locale_blank, options.except(:mode).merge(
:cur_locale => ::I18n.t(:"locales.#{locale}", :default => locale.to_s)
))
end
end
end
|