Class: Slim::Translator
- Inherits:
-
Filter
- Object
- Temple::HTML::Filter
- Filter
- Slim::Translator
show all
- Defined in:
- lib/slim/translator.rb
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
Returns a new instance of Translator.
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/slim/translator.rb', line 37
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
26
27
28
29
30
31
|
# File 'lib/slim/translator.rb', line 26
def self.i18n_key(text)
key = text.parameterize.underscore
I18n.t!(key)
rescue I18n::MissingTranslationData
text
end
|
.i18n_text(text) ⇒ Object
20
21
22
23
24
|
# File 'lib/slim/translator.rb', line 20
def self.i18n_text(text)
I18n.t!(text)
rescue I18n::MissingTranslationData
text
end
|
Instance Method Details
#call(exp) ⇒ Object
33
34
35
|
# File 'lib/slim/translator.rb', line 33
def call(exp)
options[:tr] ? super : exp
end
|
#on_slim_text(exp) ⇒ Object
49
50
51
|
# File 'lib/slim/translator.rb', line 49
def on_slim_text(exp)
[:slim, :text, @translator.call(exp)]
end
|