Class: RPV::Wiring::I18n

Inherits:
Base
  • Object
show all
Defined in:
lib/rpv/wiring/i18n.rb

Instance Method Summary collapse

Constructor Details

#initialize(args = {}, &block) ⇒ I18n

Returns a new instance of I18n.

Raises:

  • (ArgumentError)


8
9
10
11
12
# File 'lib/rpv/wiring/i18n.rb', line 8

def initialize(args = {}, &block)
  @view, @key = args[:view], args[:key]
  @block = block
  raise ArgumentError, "View field must be given" if @view.nil?
end

Instance Method Details

#update_view(model, view, presenter) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/rpv/wiring/i18n.rb', line 14

def update_view(model, view, presenter)
  args = @block.call unless @block.nil?
  if args.nil?
    send_nested(view, "#{@view}=", X18n.t(@key).to_s)
  else
    send_nested(view, "#{@view}=", X18n.t(@key, args).to_s)
  end
end