Class: Aerogel::I18n::Chainable

Inherits:
Object
  • Object
show all
Defined in:
lib/aerogel/core/i18n.rb

Overview

Chainable #t helper support class. Example:

t.aerogel.admin.welcome # => t 'aerogel.admin.welcome'
t.aerogel.admin.welcome username: 'John' # => t 'aerogel.admin.welcome', username: 'John'

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Chainable

Returns a new instance of Chainable.



107
108
109
110
# File 'lib/aerogel/core/i18n.rb', line 107

def initialize( *args )
  @path = []
  call( *args ) if args.size > 0
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



112
113
114
115
116
117
118
119
# File 'lib/aerogel/core/i18n.rb', line 112

def method_missing( name, *args )
  @path << name.to_sym
  if args.size > 0
    call( *args )
  else
    self
  end
end

Instance Method Details

#call(*args) ⇒ Object



121
122
123
# File 'lib/aerogel/core/i18n.rb', line 121

def call( *args )
  ::I18n.t translation_key, *args
end

#to_sObject



125
126
127
# File 'lib/aerogel/core/i18n.rb', line 125

def to_s()
  ::I18n.t translation_key
end

#translation_keyObject



129
130
131
# File 'lib/aerogel/core/i18n.rb', line 129

def translation_key
  @path.join(".")
end