Sha256: 2931bcc3f0d8f8b842adfd3664d3eb230d9b418e769a320d1cf4680844860e59

Contents?: true

Size: 1.02 KB

Versions: 31

Compression:

Stored size: 1.02 KB

Contents

module ActiveAdmin
  module Localizers
    class ResourceLocalizer
      class << self
        def from_resource(resource_config)
          new(resource_config.resource_name.i18n_key, resource_config.resource_label)
        end

        def translate(key, options)
          new(options.delete(:model_name), options.delete(:model)).translate(key, options)
        end
        alias_method :t, :translate
      end

      def initialize(model_name, model = nil)
        @model_name = model_name
        @model = model || model_name.to_s.titleize
      end

      def translate(key, options = {})
        scope = options.delete(:scope)
        specific_key = array_to_key('resources', @model_name, scope, key)
        defaults = [array_to_key(scope, key), key.to_s.titleize]
        ::I18n.t specific_key, options.reverse_merge(model: @model, default: defaults, scope: 'active_admin')
      end
      alias_method :t, :translate

      protected

      def array_to_key(*arr)
        arr.flatten.compact.join('.').to_sym
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 3 rubygems

Version Path
activeadmin-rb-1.5.1 lib/active_admin/localizers/resource_localizer.rb
activeadmin-2.6.0 lib/active_admin/localizers/resource_localizer.rb
activeadmin-2.5.0 lib/active_admin/localizers/resource_localizer.rb
activeadmin-2.4.0 lib/active_admin/localizers/resource_localizer.rb
activeadmin-2.3.1 lib/active_admin/localizers/resource_localizer.rb
activeadmin-2.3.0 lib/active_admin/localizers/resource_localizer.rb
activeadmin-2.2.0 lib/active_admin/localizers/resource_localizer.rb
activeadmin-2.1.0 lib/active_admin/localizers/resource_localizer.rb
activeadmin-2.0.0 lib/active_admin/localizers/resource_localizer.rb
activeadmin-rb-1.5.0 lib/active_admin/localizers/resource_localizer.rb
activeadmin-2.0.0.rc2 lib/active_admin/localizers/resource_localizer.rb
activeadmin_addons-1.7.1 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/lib/active_admin/localizers/resource_localizer.rb
activeadmin-2.0.0.rc1 lib/active_admin/localizers/resource_localizer.rb
activeadmin-rb-1.4.0 lib/active_admin/localizers/resource_localizer.rb
activeadmin_addons-1.7.0 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/lib/active_admin/localizers/resource_localizer.rb
activeadmin-1.4.3 lib/active_admin/localizers/resource_localizer.rb
activeadmin-1.4.2 lib/active_admin/localizers/resource_localizer.rb
activeadmin-1.4.1 lib/active_admin/localizers/resource_localizer.rb
activeadmin-1.4.0 lib/active_admin/localizers/resource_localizer.rb
activeadmin-1.3.1 lib/active_admin/localizers/resource_localizer.rb