Class: Translatomatic::Translator::Base Abstract
- Inherits:
-
Object
- Object
- Translatomatic::Translator::Base
- Includes:
- Util
- Defined in:
- lib/translatomatic/translator/base.rb
Overview
This class is abstract.
Base class for interfaces to translation APIs
Instance Attribute Summary collapse
-
#listener ⇒ Object
Listener for translation events.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Base
constructor
A new instance of Base.
-
#languages ⇒ Array<String>
A list of languages supported by this translator.
-
#name ⇒ String
The name of this translator.
-
#translate(strings, from, to) ⇒ Array<String>
Translate strings from one locale to another.
Constructor Details
#initialize(options = {}) ⇒ Base
Returns a new instance of Base.
14 15 16 |
# File 'lib/translatomatic/translator/base.rb', line 14 def initialize( = {}) @listener = [:listener] end |
Instance Attribute Details
#listener ⇒ Object
Listener for translation events
12 13 14 |
# File 'lib/translatomatic/translator/base.rb', line 12 def listener @listener end |
Instance Method Details
#languages ⇒ Array<String>
Returns A list of languages supported by this translator.
24 25 26 |
# File 'lib/translatomatic/translator/base.rb', line 24 def languages [] end |
#name ⇒ String
Returns The name of this translator.
19 20 21 |
# File 'lib/translatomatic/translator/base.rb', line 19 def name self.class.name.demodulize end |
#translate(strings, from, to) ⇒ Array<String>
Translate strings from one locale to another
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/translatomatic/translator/base.rb', line 33 def translate(strings, from, to) @updated_listener = false strings = [strings] unless strings.kind_of?(Array) from = locale(from) to = locale(to) return strings if from.language == to.language translated = perform_translate(strings, from, to) update_translated(translated) unless @updated_listener translated end |