Class: EacRubyUtils::Locales::ModuleI18nTranslate
- Defined in:
- lib/eac_ruby_utils/locales/module_i18n_translate.rb
Constant Summary collapse
- TRANSLATE_LOCALE_KEY =
:__locale
Instance Method Summary collapse
- #ancestor_i18n_translate(ancestor) ⇒ Object
- #ancestors_i18n_translate ⇒ Object
- #exists? ⇒ Boolean
- #i18n_key ⇒ Object
- #i18n_options ⇒ Object
- #i18n_translate ⇒ Object
- #locale ⇒ Object
- #module_entry_prefix ⇒ Object
- #on_locale(&block) ⇒ Object
- #result ⇒ Object
Instance Method Details
#ancestor_i18n_translate(ancestor) ⇒ Object
14 15 16 17 |
# File 'lib/eac_ruby_utils/locales/module_i18n_translate.rb', line 14 def ancestor_i18n_translate(ancestor) t = self.class.new(ancestor, entry_suffix, values) t.exists? ? t.i18n_translate : nil end |
#ancestors_i18n_translate ⇒ Object
19 20 21 |
# File 'lib/eac_ruby_utils/locales/module_i18n_translate.rb', line 19 def ancestors_i18n_translate the_module.ancestors.lazy.map { |v| ancestor_i18n_translate(v) }.find(&:present?) end |
#exists? ⇒ Boolean
23 24 25 |
# File 'lib/eac_ruby_utils/locales/module_i18n_translate.rb', line 23 def exists? ::I18n.exists?(i18n_key) end |
#i18n_key ⇒ Object
27 28 29 |
# File 'lib/eac_ruby_utils/locales/module_i18n_translate.rb', line 27 def i18n_key "#{module_entry_prefix}.#{entry_suffix}" end |
#i18n_options ⇒ Object
31 32 33 |
# File 'lib/eac_ruby_utils/locales/module_i18n_translate.rb', line 31 def values.except(TRANSLATE_LOCALE_KEY) end |
#i18n_translate ⇒ Object
35 36 37 |
# File 'lib/eac_ruby_utils/locales/module_i18n_translate.rb', line 35 def i18n_translate ::I18n.t(i18n_key, ) end |
#locale ⇒ Object
39 40 41 |
# File 'lib/eac_ruby_utils/locales/module_i18n_translate.rb', line 39 def locale values[TRANSLATE_LOCALE_KEY] end |
#module_entry_prefix ⇒ Object
43 44 45 |
# File 'lib/eac_ruby_utils/locales/module_i18n_translate.rb', line 43 def module_entry_prefix the_module.name.underscore.gsub('/', '.') end |
#on_locale(&block) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/eac_ruby_utils/locales/module_i18n_translate.rb', line 47 def on_locale(&block) if locale.present? on_present_locale(&block) else block.call end end |
#result ⇒ Object
55 56 57 58 59 |
# File 'lib/eac_ruby_utils/locales/module_i18n_translate.rb', line 55 def result on_locale do ancestors_i18n_translate || i18n_translate end end |