Module: Super::Useful::I19
- Defined in:
- lib/super/useful/i19.rb
Class Method Summary collapse
- .build_chain(prefix, optional, suffix) ⇒ Object
- .chain_to_i18n(chain) ⇒ Object
- .i18n_with_fallback(prefix, optional, suffix) ⇒ Object
Class Method Details
.build_chain(prefix, optional, suffix) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/super/useful/i19.rb', line 8 def build_chain(prefix, optional, suffix) prefix = Array(prefix) optional = Array(optional) suffix = Array(suffix) result = [] (optional.size + 1).times do lookup = [prefix, optional, suffix].flatten.join(".").to_sym result.push(lookup) optional.pop end result end |
.chain_to_i18n(chain) ⇒ Object
24 25 26 27 28 |
# File 'lib/super/useful/i19.rb', line 24 def chain_to_i18n(chain) head, *tail = chain [head, {default: tail}] end |
.i18n_with_fallback(prefix, optional, suffix) ⇒ Object
30 31 32 |
# File 'lib/super/useful/i19.rb', line 30 def i18n_with_fallback(prefix, optional, suffix) chain_to_i18n(build_chain(prefix, optional, suffix)) end |