Skip to content

Commit

Permalink
Errors messages are now moved from :activerecord.errors to simply :er…
Browse files Browse the repository at this point in the history
…rors on I18n yml files.
  • Loading branch information
josevalim committed Jan 7, 2010
1 parent a323b83 commit 190ce3a
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 228 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ gem "rails", "3.0.pre", :path => "railties"
end end


# AS # AS
gem "i18n", ">= 0.3.0" gem "i18n", "0.3.3"


# AR # AR
gem "arel", "0.2.pre", :git => "git://github.com/rails/arel.git" gem "arel", "0.2.pre", :git => "git://github.com/rails/arel.git"
Expand Down
5 changes: 2 additions & 3 deletions activemodel/lib/active_model/errors.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ def full_messages
else else
attr_name = attribute.to_s.gsub('.', '_').humanize attr_name = attribute.to_s.gsub('.', '_').humanize
attr_name = @base.class.human_attribute_name(attribute, :default => attr_name) attr_name = @base.class.human_attribute_name(attribute, :default => attr_name)
options = { :default => "{{attribute}} {{message}}", :attribute => attr_name, options = { :default => "{{attribute}} {{message}}", :attribute => attr_name }
:scope => @base.class.i18n_scope }


messages.each do |m| messages.each do |m|
full_messages << I18n.t(:"errors.format", options.merge(:message => m)) full_messages << I18n.t(:"errors.format", options.merge(:message => m))
Expand Down Expand Up @@ -153,7 +152,7 @@ def generate_message(attribute, message = :invalid, options = {})
:model => @base.class.model_name.human, :model => @base.class.model_name.human,
:attribute => @base.class.human_attribute_name(attribute), :attribute => @base.class.human_attribute_name(attribute),
:value => value, :value => value,
:scope => [@base.class.i18n_scope, :errors] :scope => [:errors]
}.merge(options) }.merge(options)


I18n.translate(key, options) I18n.translate(key, options)
Expand Down
49 changes: 24 additions & 25 deletions activemodel/lib/active_model/locale/en.yml
Original file line number Original file line Diff line number Diff line change
@@ -1,27 +1,26 @@
en: en:
activemodel: errors:
errors: # The default format use in full error messages.
# model.errors.full_messages format. format: "{{attribute}} {{message}}"
format: "{{attribute}} {{message}}"


# The values :model, :attribute and :value are always available for interpolation # The values :model, :attribute and :value are always available for interpolation
# The value :count is available when applicable. Can be used for pluralization. # The value :count is available when applicable. Can be used for pluralization.
messages: messages:
inclusion: "is not included in the list" inclusion: "is not included in the list"
exclusion: "is reserved" exclusion: "is reserved"
invalid: "is invalid" invalid: "is invalid"
confirmation: "doesn't match confirmation" confirmation: "doesn't match confirmation"
accepted: "must be accepted" accepted: "must be accepted"
empty: "can't be empty" empty: "can't be empty"
blank: "can't be blank" blank: "can't be blank"
too_long: "is too long (maximum is {{count}} characters)" too_long: "is too long (maximum is {{count}} characters)"
too_short: "is too short (minimum is {{count}} characters)" too_short: "is too short (minimum is {{count}} characters)"
wrong_length: "is the wrong length (should be {{count}} characters)" wrong_length: "is the wrong length (should be {{count}} characters)"
not_a_number: "is not a number" not_a_number: "is not a number"
greater_than: "must be greater than {{count}}" greater_than: "must be greater than {{count}}"
greater_than_or_equal_to: "must be greater than or equal to {{count}}" greater_than_or_equal_to: "must be greater than or equal to {{count}}"
equal_to: "must be equal to {{count}}" equal_to: "must be equal to {{count}}"
less_than: "must be less than {{count}}" less_than: "must be less than {{count}}"
less_than_or_equal_to: "must be less than or equal to {{count}}" less_than_or_equal_to: "must be less than or equal to {{count}}"
odd: "must be odd" odd: "must be odd"
even: "must be even" even: "must be even"
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -7,42 +7,6 @@ class I18nGenerateMessageValidationTest < ActiveModel::TestCase
def setup def setup
Person.reset_callbacks(:validate) Person.reset_callbacks(:validate)
@person = Person.new @person = Person.new

@old_load_path, @old_backend = I18n.load_path, I18n.backend
I18n.load_path.clear
I18n.backend = I18n::Backend::Simple.new

I18n.backend.store_translations :'en', {
:activemodel => {
:errors => {
:messages => {
:inclusion => "is not included in the list",
:exclusion => "is reserved",
:invalid => "is invalid",
:confirmation => "doesn't match confirmation",
:accepted => "must be accepted",
:empty => "can't be empty",
:blank => "can't be blank",
:too_long => "is too long (maximum is {{count}} characters)",
:too_short => "is too short (minimum is {{count}} characters)",
:wrong_length => "is the wrong length (should be {{count}} characters)",
:not_a_number => "is not a number",
:greater_than => "must be greater than {{count}}",
:greater_than_or_equal_to => "must be greater than or equal to {{count}}",
:equal_to => "must be equal to {{count}}",
:less_than => "must be less than {{count}}",
:less_than_or_equal_to => "must be less than or equal to {{count}}",
:odd => "must be odd",
:even => "must be even"
}
}
}
}
end

def teardown
I18n.load_path.replace @old_load_path
I18n.backend = @old_backend
end end


# validates_inclusion_of: generate_message(attr_name, :inclusion, :default => configuration[:message], :value => value) # validates_inclusion_of: generate_message(attr_name, :inclusion, :default => configuration[:message], :value => value)
Expand Down
Loading

0 comments on commit 190ce3a

Please sign in to comment.