Class: Slim::Translator Private
- 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
- .i18n_key(text) ⇒ Object private
- .i18n_text(text) ⇒ Object private
Instance Method Summary collapse
- #call(exp) ⇒ Object private
-
#initialize(opts = {}) ⇒ Translator
constructor
private
A new instance of Translator.
- #on_slim_text(type, exp) ⇒ Object private
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.
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/slim/translator.rb', line 39 def initialize(opts = {}) super case [:tr_mode] when :static @translator = StaticTranslator.new(tr_fn: [:tr_fn]) when :dynamic @translator = DynamicTranslator.new(tr_fn: [:tr_fn]) else raise ArgumentError, "Invalid translator mode #{[: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.
28 29 30 31 32 33 |
# File 'lib/slim/translator.rb', line 28 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.
22 23 24 25 26 |
# File 'lib/slim/translator.rb', line 22 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.
35 36 37 |
# File 'lib/slim/translator.rb', line 35 def call(exp) [: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.
51 52 53 |
# File 'lib/slim/translator.rb', line 51 def on_slim_text(type, exp) [:slim, :text, type, @translator.call(exp)] end |