diff --git a/Gemfile b/Gemfile index 5e900fb..6a0a4f3 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ -source :rubygems +source 'https://rubygems.org' gem 'rake' gem 'i18n', '>= 0.5.0' diff --git a/lib/russian.rb b/lib/russian.rb index 7c426eb..0b091c4 100644 --- a/lib/russian.rb +++ b/lib/russian.rb @@ -38,13 +38,13 @@ def init_i18n # See I18n::translate def translate(key, options = {}) - I18n.translate(key, options.merge({ :locale => LOCALE })) - end + I18n.translate(key, **options.merge({ :locale => LOCALE })) + end alias :t :translate # See I18n::localize def localize(object, options = {}) - I18n.localize(object, options.merge({ :locale => LOCALE })) + I18n.localize(object, **options.merge({ :locale => LOCALE })) end alias :l :localize diff --git a/lib/russian/active_model_ext/custom_error_message.rb b/lib/russian/active_model_ext/custom_error_message.rb deleted file mode 100644 index 4698409..0000000 --- a/lib/russian/active_model_ext/custom_error_message.rb +++ /dev/null @@ -1,70 +0,0 @@ -# -*- encoding: utf-8 -*- - -if defined?(ActiveModel::Errors) - module ActiveModel - class Errors - # Redefine the ActiveModel::Errors.full_messages method: - # Returns all the full error messages in an array. 'Base' messages are handled as usual. - # Non-base messages are prefixed with the attribute name as usual UNLESS they begin with '^' - # in which case the attribute name is omitted. - # E.g. validates_acceptance_of :accepted_terms, :message => '^Please accept the terms of service' - # - # Переопределяет метод ActiveModel::Errors.full_messages. Сообщения об ошибках для атрибутов - # теперь не имеют префикса с названием атрибута если в сообщении об ошибке первым символом указан "^". - # - # Так, например, - # - # validates_acceptance_of :accepted_terms, :message => 'нужно принять соглашение' - # - # даст сообщение - # - # Accepted terms нужно принять соглашение - # - # однако, - # - # validates_acceptance_of :accepted_terms, :message => '^Нужно принять соглашение' - # - # даст сообщение - # - # Нужно принять соглашение - # - # - # Returns all the full error messages in an array. - # - # class Company - # validates_presence_of :name, :address, :email - # validates_length_of :name, :in => 5..30 - # end - # - # company = Company.create(:address => '123 First St.') - # company.errors.full_messages # => - # ["Name is too short (minimum is 5 characters)", "Name can't be blank", "Address can't be blank"] - def full_messages - full_messages = [] - - each do |attribute, messages| - messages = Array.wrap(messages) - next if messages.empty? - - if attribute == :base - messages.each {|m| full_messages << m } - else - attr_name = attribute.to_s.gsub('.', '_').humanize - attr_name = @base.class.human_attribute_name(attribute, :default => attr_name) - options = { :attribute => attr_name, :default => "%{attribute} %{message}" } - - messages.each do |m| - if m =~ /^\^/ - full_messages << m[1..-1] - else - full_messages << I18n.t(:"errors.format", options.merge(:message => m)) - end - end - end - end - - full_messages - end - end - end -end # if defined? diff --git a/lib/russian/russian_rails.rb b/lib/russian/russian_rails.rb index f036547..a7de112 100644 --- a/lib/russian/russian_rails.rb +++ b/lib/russian/russian_rails.rb @@ -1,8 +1,4 @@ # Rails hacks -if defined?(ActiveModel) - require 'active_model_ext/custom_error_message' -end - if defined?(ActionView::Helpers) - require 'action_view_ext/helpers/date_helper' + require 'action_view_ext/helpers/date_helper' end