Royce icon indicating copy to clipboard operation
Royce copied to clipboard

i18n

Open chiwenchen opened this issue 7 years ago • 1 comments

Hi there, is anyone knows how to set i18n translate for royce role?

chiwenchen avatar May 15 '17 07:05 chiwenchen

That's what I did for my app :

module MyApp
  module CoreExt
    module RoyceRolePatch
      def self.included(base)
        base.send(:prepend, InstanceMethods)
        base.class_eval do
          scope :order_by_name, -> { order(name: :asc) }
        end
      end

      module InstanceMethods

        def to_s
          super.capitalize
        end

      end
    end
  end
end


unless Royce::Role.included_modules.include?(MyApp::CoreExt::RoyceRolePatch)
  Royce::Role.send(:include, MyApp::CoreExt::RoyceRolePatch)
end

It adds a scope order_by_name and override to_s method. You could change it to I18n.t("roles.#{name}")

n-rodriguez avatar May 20 '17 19:05 n-rodriguez