Class: PhraseApp::InContextEditor::Delegate::I18nDelegate
- Defined in:
- lib/phraseapp-in-context-editor-ruby/delegate/i18n_delegate.rb
Instance Attribute Summary collapse
-
#api_client ⇒ Object
Returns the value of attribute api_client.
-
#display_key ⇒ Object
Returns the value of attribute display_key.
-
#fallback_keys ⇒ Object
Returns the value of attribute fallback_keys.
-
#key ⇒ Object
Returns the value of attribute key.
-
#options ⇒ Object
Returns the value of attribute options.
-
#original_args ⇒ Object
Returns the value of attribute original_args.
Instance Method Summary collapse
-
#initialize(key, options = {}, original_args = nil) ⇒ I18nDelegate
constructor
A new instance of I18nDelegate.
- #method_missing(*args, &block) ⇒ Object
Methods inherited from Base
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, ={}, original_args=nil) @key = key @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_client ⇒ Object
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_key ⇒ Object
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_keys ⇒ Object
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 |
#key ⇒ Object
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 |
#options ⇒ Object
Returns the value of attribute options.
15 16 17 |
# File 'lib/phraseapp-in-context-editor-ruby/delegate/i18n_delegate.rb', line 15 def @options end |
#original_args ⇒ Object
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 |