class Slim::Translator

@api private

Public Class Methods

i18n_key(text) click to toggle source
# 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) click to toggle source
# File lib/slim/translator.rb, line 21
def self.i18n_text(text)
  I18n.t!(text)
rescue I18n::MissingTranslationData
  text
end
new(opts = {}) click to toggle source
Calls superclass method
# 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

Public Instance Methods

call(exp) click to toggle source
Calls superclass method
# File lib/slim/translator.rb, line 34
def call(exp)
  options[:tr] ? super : exp
end
on_slim_text(type, exp) click to toggle source
# File lib/slim/translator.rb, line 50
def on_slim_text(type, exp)
  [:slim, :text, type, @translator.call(exp)]
end