Class: Slim::Translator Private

Inherits:
Filter
  • Object
show all
Defined in:
lib/slim/translator.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Defined Under Namespace

Classes: DynamicTranslator, StaticTranslator

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Filter

#on_slim_control, #on_slim_embedded, #on_slim_output

Constructor Details

#initialize(opts = {}) ⇒ Translator

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Translator



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/slim/translator.rb', line 38

def initialize(opts = {})
  super
  case options[:tr_mode]
  when :static
    @translator = StaticTranslator.new(tr_fn: options[:tr_fn])
  when :dynamic
    @translator = DynamicTranslator.new(tr_fn: options[:tr_fn])
  else
    raise ArgumentError, "Invalid translator mode #{options[:tr_mode].inspect}"
  end
end

Class Method Details

.i18n_key(text) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



27
28
29
30
31
32
# File 'lib/slim/translator.rb', line 27

def self.i18n_key(text)
  key = text.parameterize.underscore
  I18n.t!(key)
rescue I18n::MissingTranslationData
  text
end

.i18n_text(text) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



21
22
23
24
25
# File 'lib/slim/translator.rb', line 21

def self.i18n_text(text)
  I18n.t!(text)
rescue I18n::MissingTranslationData
  text
end

Instance Method Details

#call(exp) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



34
35
36
# File 'lib/slim/translator.rb', line 34

def call(exp)
  options[:tr] ? super : exp
end

#on_slim_text(type, exp) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



50
51
52
# File 'lib/slim/translator.rb', line 50

def on_slim_text(type, exp)
  [:slim, :text, type, @translator.call(exp)]
end