Sha256: b759d566a86309aeae22c5b909397bb2b74bf2825e71c5f1279d6f3ea2e5e2e6

Contents?: true

Size: 695 Bytes

Versions: 5

Compression:

Stored size: 695 Bytes

Contents

module RailsCoreExtensions
  module Translations
    extend ActiveSupport::Concern

    module ClassMethods
      def translate(key, options = {})
        I18n.translate key, **options.merge(scope: translation_key)
      end

      def translation_key
        @translation_key ||= base_translation_class.name.tableize.singularize.gsub('/', '.')
      end

      def base_translation_class
        return base_class if defined?(ActiveRecord) && ancestors.include?(ActiveRecord::Base)
        self
      end

      def t(key, options = {})
        self.translate(key, options)
      end
    end

    private

    def t(key, options = {})
      self.class.translate(key, options)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rails_core_extensions-0.15.0 lib/rails_core_extensions/translations.rb
rails_core_extensions-0.14.0 lib/rails_core_extensions/translations.rb
rails_core_extensions-0.13.2 lib/rails_core_extensions/translations.rb
rails_core_extensions-0.13.1 lib/rails_core_extensions/translations.rb
rails_core_extensions-0.13.0 lib/rails_core_extensions/translations.rb