diff --git a/app/models/category.rb b/app/models/category.rb index ad6605f..0623c73 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -1,12 +1,12 @@ class Category < ActiveRecord::Base - validates_exclusion_of :slug, :in => [ 'index' ], :message => N_('%{fn} cannot be like that.') + validates_exclusion_of :slug, :in => [ 'index' ], :message => N_('%{fn} cannot be like that.').fix_i18n validates_presence_of :name, :environment_id - validates_uniqueness_of :slug,:scope => [ :environment_id, :parent_id ], :message => N_('%{fn} is already being used by another category.') + validates_uniqueness_of :slug,:scope => [ :environment_id, :parent_id ], :message => N_('%{fn} is already being used by another category.').fix_i18n belongs_to :environment validates_inclusion_of :display_color, :in => [ 1, 2, 3, 4, nil ] - validates_uniqueness_of :display_color, :scope => :environment_id, :if => (lambda { |cat| ! cat.display_color.nil? }), :message => N_('%{fn} was already assigned to another category.') + validates_uniqueness_of :display_color, :scope => :environment_id, :if => (lambda { |cat| ! cat.display_color.nil? }), :message => N_('%{fn} was already assigned to another category.').fix_i18n # Finds all top level categories for a given environment. named_scope :top_level_for, lambda { |environment| diff --git a/app/models/change_password.rb b/app/models/change_password.rb index a9d6510..4544ccd 100644 --- a/app/models/change_password.rb +++ b/app/models/change_password.rb @@ -30,10 +30,10 @@ class ChangePassword < Task unless data.login.blank? || data.email.blank? user = User.find_by_login_and_environment_id(data.login, data.environment_id) if user.nil? - data.errors.add(:login, _('%{fn} is not a valid username.')) + data.errors.add(:login, _('%{fn} is not a valid username.').fix_i18n) else if user.email != data.email - data.errors.add(:email, _('%{fn} is invalid.')) + data.errors.add(:email) end end end diff --git a/app/models/comment.rb b/app/models/comment.rb index 9fb59e7..f83be6e 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -17,7 +17,7 @@ class Comment < ActiveRecord::Base validates_presence_of :author_id, :if => (lambda { |rec| rec.name.blank? && rec.email.blank? }) validates_each :name do |rec,attribute,value| if rec.author_id && (!rec.name.blank? || !rec.email.blank?) - rec.errors.add(:name, _('%{fn} can only be informed for unauthenticated authors')) + rec.errors.add(:name, _('%{fn} can only be informed for unauthenticated authors').fix_i18n) end end diff --git a/app/models/community.rb b/app/models/community.rb index 3c3f7e7..cb028b7 100644 --- a/app/models/community.rb +++ b/app/models/community.rb @@ -34,7 +34,7 @@ class Community < Organization super self.required_fields.each do |field| if self.send(field).blank? - self.errors.add(field, _('%{fn} can\'t be blank')) + self.errors.add_on_blank(field) end end end diff --git a/app/models/create_community.rb b/app/models/create_community.rb index 1db2c4c..214145f 100644 --- a/app/models/create_community.rb +++ b/app/models/create_community.rb @@ -16,7 +16,7 @@ class CreateCommunity < Task def validate self.environment.required_community_fields.each do |field| if self.send(field).blank? - self.errors.add(field, _('%{fn} can\'t be blank')) + self.errors.add_on_blank(field) end end end diff --git a/app/models/create_enterprise.rb b/app/models/create_enterprise.rb index 3998934..df11e4b 100644 --- a/app/models/create_enterprise.rb +++ b/app/models/create_enterprise.rb @@ -40,12 +40,12 @@ class CreateEnterprise < Task if self.region && self.target unless self.region.validators.include?(self.target) || self.target_type == "Environment" - self.errors.add(:target, '%{fn} is not a validator for the chosen region') + self.errors.add(:target, _('%{fn} is not a validator for the chosen region').fix_i18n) end end if self.status != Task::Status::CANCELLED && self.identifier && Profile.exists?(:identifier => self.identifier) - self.errors.add(:identifier, '%{fn} is already being as identifier by another enterprise, organization or person.') + self.errors.add(:identifier, _('%{fn} is already being as identifier by another enterprise, organization or person.').fix_i18n) end end diff --git a/app/models/domain.rb b/app/models/domain.rb index a465fdc..6c7d0f0 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -10,14 +10,14 @@ class Domain < ActiveRecord::Base # name must be a sequence of word characters (a to z, plus 0 to 9, # plus '_'). Letters must be lowercase - validates_format_of :name, :with => /^([a-z0-9_-]+\.)+[a-z0-9_-]+$/, :message => N_('%{fn} must be composed only of lowercase latters (a to z), numbers (0 to 9), "_" and "-"') + validates_format_of :name, :with => /^([a-z0-9_-]+\.)+[a-z0-9_-]+$/, :message => N_('%{fn} must be composed only of lowercase latters (a to z), numbers (0 to 9), "_" and "-"').fix_i18n # checks validations that could not be expressed using Rails' predefined # validations. In particular: # * name must not start with 'www.' def validate if self.name =~ /^www\./ - self.errors.add(:name, _('%{fn} must not start with www.')) + self.errors.add(:name, _('%{fn} must not start with www.').fix_i18n) end end diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 3359e16..2b6df9a 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -46,7 +46,7 @@ class Enterprise < Organization super self.required_fields.each do |field| if self.send(field).blank? - self.errors.add(field, _("%{fn} can't be blank")) + self.errors.add_on_blank(field) end end end diff --git a/app/models/event.rb b/app/models/event.rb index b6722ff..b9ebd8d 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -22,7 +22,7 @@ class Event < Article validates_each :start_date do |event,field,value| if event.end_date && event.start_date && event.start_date > event.end_date - event.errors.add(:start_date, _('%{fn} cannot come before end date.')) + event.errors.add(:start_date, _('%{fn} cannot come before end date.').fix_i18n) end end diff --git a/app/models/image.rb b/app/models/image.rb index 8e6f30b..a88bc0c 100644 --- a/app/models/image.rb +++ b/app/models/image.rb @@ -17,7 +17,7 @@ class Image < ActiveRecord::Base :icon => '20x20!' }, :max_size => 5.megabytes # remember to update validate message below - validates_attachment :size => N_("%{fn} of uploaded file was larger than the maximum size of 5.0 MB") + validates_attachment :size => N_("%{fn} of uploaded file was larger than the maximum size of 5.0 MB").fix_i18n delay_attachment_fu_thumbnails diff --git a/app/models/person.rb b/app/models/person.rb index b232d02..c5fff58 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -197,7 +197,7 @@ class Person < Profile validates_each :email, :on => :update do |record,attr,value| if User.find(:first, :conditions => ['email = ? and id != ? and environment_id = ?', value, record.user.id, record.environment.id]) - record.errors.add(attr, _('%{fn} is already used by other user')) + record.errors.add(attr, _('%{fn} is already used by other user').fix_i18n) end end diff --git a/app/models/uploaded_file.rb b/app/models/uploaded_file.rb index 2f980ca..57e6141 100644 --- a/app/models/uploaded_file.rb +++ b/app/models/uploaded_file.rb @@ -50,7 +50,7 @@ class UploadedFile < Article :thumbnail_class => Thumbnail, :max_size => 5.megabytes # remember to update validate message below - validates_attachment :size => N_("%{fn} of uploaded file was larger than the maximum size of 5.0 MB") + validates_attachment :size => N_("%{fn} of uploaded file was larger than the maximum size of 5.0 MB").fix_i18n delay_attachment_fu_thumbnails diff --git a/app/models/user.rb b/app/models/user.rb index 9775754..e2ea1f5 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -100,7 +100,7 @@ class User < ActiveRecord::Base before_save :encrypt_password validates_format_of :email, :with => Noosfero::Constants::EMAIL_FORMAT, :if => (lambda {|user| !user.email.blank?}) - validates_inclusion_of :terms_accepted, :in => [ '1' ], :if => lambda { |u| ! u.terms_of_use.blank? }, :message => N_('%{fn} must be checked in order to signup.') + validates_inclusion_of :terms_accepted, :in => [ '1' ], :if => lambda { |u| ! u.terms_of_use.blank? }, :message => N_('%{fn} must be checked in order to signup.').fix_i18n # Authenticates a user by their login name and unencrypted password. Returns the user or nil. def self.authenticate(login, password, environment = nil) diff --git a/lib/noosfero/core_ext/string.rb b/lib/noosfero/core_ext/string.rb index fadf285..943489e 100644 --- a/lib/noosfero/core_ext/string.rb +++ b/lib/noosfero/core_ext/string.rb @@ -40,4 +40,8 @@ class String transliterate.downcase.gsub(/[^\w~\s:;+=_."'`-]/, '').gsub(/[\s:;+=_"'`-]+/, '-').gsub(/-$/, '').gsub(/^-/, '').to_s end + def fix_i18n + self.sub('{fn} ', '') + end + end diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb index e6138fa..82ab6de 100644 --- a/test/unit/comment_test.rb +++ b/test/unit/comment_test.rb @@ -60,6 +60,7 @@ class CommentTest < ActiveSupport::TestCase c1.name = 'my name' c1.valid? assert c1.errors.invalid?(:name) + assert_no_match /\{fn\}/, c1.errors.on(:name) end should 'update counter cache in article' do diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb index 3609fee..6b9c495 100644 --- a/test/unit/person_test.rb +++ b/test/unit/person_test.rb @@ -133,6 +133,7 @@ class PersonTest < ActiveSupport::TestCase other.email = 'user@domain.com' other.valid? assert other.errors.invalid?(:email) + assert_no_match /\{fn\}/, other.errors.on(:email) end should 'be able to use an e-mail already used in other environment' do diff --git a/vendor/plugins/validates_as_cnpj/lib/validates_as_cnpj.rb b/vendor/plugins/validates_as_cnpj/lib/validates_as_cnpj.rb index 1662b15..47220b7 100755 --- a/vendor/plugins/validates_as_cnpj/lib/validates_as_cnpj.rb +++ b/vendor/plugins/validates_as_cnpj/lib/validates_as_cnpj.rb @@ -62,14 +62,14 @@ module ActiveRecord module Validations module ClassMethods def validates_as_cnpj(*attr_names) - configuration = { :message => "%{fn} is invalid" } + configuration = { } configuration.update(attr_names.pop) if attr_names.last.is_a?(Hash) validates_each(attr_names, configuration) do |record, attr_name, value| next if value.blank? unless ValidaCNPJ::valida_cnpj(value) - record.errors.add(attr_name, configuration[:message]) + record.errors.add(attr_name) end end end -- libgit2 0.21.2