Class: Pseudolocalization::I18n::Backend

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(original_backend) {|_self| ... } ⇒ Backend

Returns a new instance of Backend.

Yields:

  • (_self)

Yield Parameters:



10
11
12
13
14
# File 'lib/pseudolocalization.rb', line 10

def initialize(original_backend)
  @original_backend = original_backend
  @ignores = []
  yield self if block_given?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/pseudolocalization.rb', line 16

def method_missing(name, *args, &block)
  if respond_to_missing?(name)
    original_backend.public_send(name, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#ignoresObject

Returns the value of attribute ignores.



8
9
10
# File 'lib/pseudolocalization.rb', line 8

def ignores
  @ignores
end

#original_backendObject (readonly)

Returns the value of attribute original_backend.



7
8
9
# File 'lib/pseudolocalization.rb', line 7

def original_backend
  @original_backend
end

Instance Method Details

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/pseudolocalization.rb', line 24

def respond_to_missing?(name, include_private = false)
  original_backend.respond_to?(name) || super
end

#translate(locale, key, options) ⇒ Object



28
29
30
31
32
# File 'lib/pseudolocalization.rb', line 28

def translate(locale, key, options)
  return original_backend.translate(locale, key, options) if key_ignored?(key)

  ::Pseudolocalization::I18n::Pseudolocalizer.pseudolocalize(original_backend.translate(locale, key, options))
end

#translationsObject



34
35
36
37
38
39
# File 'lib/pseudolocalization.rb', line 34

def translations
  original = original_backend.translations
  original.transform_values do |locale_translations|
    pseudolocalize_node(locale_translations)
  end
end