Module: Noticed::Translation

Extended by:
ActiveSupport::Concern
Included in:
Base
Defined in:
lib/noticed/translation.rb

Instance Method Summary collapse

Instance Method Details

#class_scopeObject



10
11
12
# File 'lib/noticed/translation.rb', line 10

def class_scope
  self.class.name.underscore.tr("/", ".")
end

#i18n_scopeObject

Returns the i18n_scope for the class. Overwrite if you want custom lookup.



6
7
8
# File 'lib/noticed/translation.rb', line 6

def i18n_scope
  :notifications
end

#scope_translation_key(key) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/noticed/translation.rb', line 23

def scope_translation_key(key)
  if key.to_s.start_with?(".")
    "#{i18n_scope}.#{class_scope}#{key}"
  else
    key
  end
end

#translate(key, **options) ⇒ Object Also known as: t



14
15
16
17
18
19
20
# File 'lib/noticed/translation.rb', line 14

def translate(key, **options)
  if defined?(::ActiveSupport::HtmlSafeTranslation)
    ActiveSupport::HtmlSafeTranslation.translate scope_translation_key(key), **options
  else
    I18n.translate scope_translation_key(key), **options
  end
end