Class: Class

Inherits:
Object show all
Defined in:
lib/avm/patches/class/i18n.rb

Constant Summary collapse

TRANSLATE_LOCALE_KEY =
:__locale

Instance Method Summary collapse

Instance Method Details

#on_i18n_locale(locale) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/avm/patches/class/i18n.rb', line 22

def on_i18n_locale(locale)
  old_locale = ::I18n.locale
  begin
    ::I18n.locale = locale
    yield
  ensure
    ::I18n.locale = old_locale
  end
end

#translate(entry_suffix, values = {}) ⇒ Object



8
9
10
11
12
# File 'lib/avm/patches/class/i18n.rb', line 8

def translate(entry_suffix, values = {})
  on_i18n_locale(values.delete(TRANSLATE_LOCALE_KEY)) do
    ::I18n.translate(translate_entry_full(entry_suffix), values)
  end
end

#translate_entry_full(entry_suffix) ⇒ Object



14
15
16
# File 'lib/avm/patches/class/i18n.rb', line 14

def translate_entry_full(entry_suffix)
  "#{translate_entry_self_prefix}.#{entry_suffix}"
end

#translate_entry_self_prefixObject



18
19
20
# File 'lib/avm/patches/class/i18n.rb', line 18

def translate_entry_self_prefix
  name.underscore.gsub('/', '.')
end