Class: PhraseApp::InContextEditor::Delegate::I18nDelegate

Inherits:
Base
  • Object
show all
Defined in:
lib/phraseapp-in-context-editor-ruby/delegate/i18n_delegate.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

log, #to_s

Constructor Details

#initialize(key, options = {}, original_args = nil) ⇒ I18nDelegate

Returns a new instance of I18nDelegate.



9
10
11
12
13
14
15
# File 'lib/phraseapp-in-context-editor-ruby/delegate/i18n_delegate.rb', line 9

def initialize(key, options = {}, original_args = nil)
  @key = key
  @options = options
  @original_args = original_args
  @display_key = @key
  super(decorated_key_name)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args, &block) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/phraseapp-in-context-editor-ruby/delegate/i18n_delegate.rb', line 17

def method_missing(*args, &block)
  self.class.log "Trying to execute missing method ##{args.first} on key #{@key}"
  if @key.respond_to?(args.first)
    to_s.send(*args)
  else
    data = [@key]
    if data.respond_to?(args.first)
      data.send(*args, &block)
    else
      self.class.log "You tried to execute the missing method ##{args.first} on key #{@key} which is not supported. Please make sure you treat your translations as strings only."
      original_translation = ::I18n.translate_without_phraseapp(*@original_args, **@options)
      original_translation.send(*args, &block)
    end
  end
end

Instance Attribute Details

#display_keyObject

Returns the value of attribute display_key.



7
8
9
# File 'lib/phraseapp-in-context-editor-ruby/delegate/i18n_delegate.rb', line 7

def display_key
  @display_key
end

#keyObject

Returns the value of attribute key.



7
8
9
# File 'lib/phraseapp-in-context-editor-ruby/delegate/i18n_delegate.rb', line 7

def key
  @key
end