Module: RailsCoreExtensions::Translations::ClassMethods

Defined in:
lib/rails_core_extensions/translations.rb

Instance Method Summary collapse

Instance Method Details

#base_translation_classObject



14
15
16
17
# File 'lib/rails_core_extensions/translations.rb', line 14

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

#t(key, options = {}) ⇒ Object



19
20
21
# File 'lib/rails_core_extensions/translations.rb', line 19

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

#translate(key, options = {}) ⇒ Object



6
7
8
# File 'lib/rails_core_extensions/translations.rb', line 6

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

#translation_keyObject



10
11
12
# File 'lib/rails_core_extensions/translations.rb', line 10

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