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.



17
18
19
20
21
22
23
# File 'lib/phraseapp-in-context-editor-ruby/delegate/i18n_delegate.rb', line 17

def initialize(key, options={}, original_args=nil)
  @key = key
  @options = options
  @original_args = original_args
  @display_key = DisplayableKeyIdentifier.new(api_wrapper).identify(@key, @options)
  super(decorated_key_name)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args, &block) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/phraseapp-in-context-editor-ruby/delegate/i18n_delegate.rb', line 25

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 = translation_or_subkeys
    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)
      original_translation.send(*args, &block)
    end
  end
end

Instance Attribute Details

#api_clientObject

Returns the value of attribute api_client.



15
16
17
# File 'lib/phraseapp-in-context-editor-ruby/delegate/i18n_delegate.rb', line 15

def api_client
  @api_client
end

#display_keyObject

Returns the value of attribute display_key.



15
16
17
# File 'lib/phraseapp-in-context-editor-ruby/delegate/i18n_delegate.rb', line 15

def display_key
  @display_key
end

#fallback_keysObject

Returns the value of attribute fallback_keys.



15
16
17
# File 'lib/phraseapp-in-context-editor-ruby/delegate/i18n_delegate.rb', line 15

def fallback_keys
  @fallback_keys
end

#keyObject

Returns the value of attribute key.



15
16
17
# File 'lib/phraseapp-in-context-editor-ruby/delegate/i18n_delegate.rb', line 15

def key
  @key
end

#optionsObject

Returns the value of attribute options.



15
16
17
# File 'lib/phraseapp-in-context-editor-ruby/delegate/i18n_delegate.rb', line 15

def options
  @options
end

#original_argsObject

Returns the value of attribute original_args.



15
16
17
# File 'lib/phraseapp-in-context-editor-ruby/delegate/i18n_delegate.rb', line 15

def original_args
  @original_args
end