Class: Traducto::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/traducto/base.rb

Overview

************************************************************************************* Base helper methods to add path to lazy lookup and allow formatting. *************************************************************************************

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rails_helpers) ⇒ Base

Returns a new instance of Base.



11
12
13
14
15
16
17
# File 'lib/traducto/base.rb', line 11

def initialize(rails_helpers)
  @rails_helpers = rails_helpers

  init_state

  set_base_actions
end

Instance Attribute Details

#rails_helpersObject (readonly)

Returns the value of attribute rails_helpers.



6
7
8
# File 'lib/traducto/base.rb', line 6

def rails_helpers
  @rails_helpers
end

Instance Method Details

#add_action(action) ⇒ Object



19
20
21
# File 'lib/traducto/base.rb', line 19

def add_action(action)
  @actions << action
end

#translate(key, options = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/traducto/base.rb', line 23

def translate(key, options={})
  init_state key, options

  lazy_translate if lazy_lookup?

  i18n_translate @base_key if translation_missing?

  format

  if @text.is_a? String
    @text.html_safe
  else
    @text
  end
end