Module: Lit::FrontendHelper::TranslationKeyWrapper

Included in:
Lit::FrontendHelper
Defined in:
app/helpers/lit/frontend_helper.rb

Instance Method Summary collapse

Instance Method Details

#missing_translation(key, options) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'app/helpers/lit/frontend_helper.rb', line 27

def missing_translation(key, options)
  # We try to humanize the key. Rails will do
  # it anyway in below call to super, but then it will wrap it also in
  # translation_missing span.
  # Humanizing key should be last resort
  if Lit::Services::HumanizeService.should_humanize?(key)
    return Lit::Services::HumanizeService.humanize_and_cache(key, options)
  end

  super(key, options)
end

#pluralized_key(key, count) ⇒ Object



16
17
18
19
20
21
# File 'app/helpers/lit/frontend_helper.rb', line 16

def pluralized_key(key, count)
  pluralizer = I18n.backend.send(:pluralizer, locale)
  return unless pluralizer.respond_to?(:call)
  last = count.zero? ? :zero : pluralizer.call(count)
  format '%<key>s.%<last>s', key: key, last: last
end

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



23
24
25
# File 'app/helpers/lit/frontend_helper.rb', line 23

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

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



5
6
7
8
9
10
11
12
13
14
# File 'app/helpers/lit/frontend_helper.rb', line 5

def translate(key, options = {})
  count = options[:count]
  options = options.with_indifferent_access
  key = scope_key_by_partial(key)
  key = pluralized_key(key, count) if count

  content = super(key, **options.symbolize_keys)
  content = get_translateable_span(key, content) if !options[:skip_lit] && lit_authorized?
  content
end