Class: Translatomatic::Provider::Base Abstract
- Inherits:
-
Object
- Object
- Translatomatic::Provider::Base
- Includes:
- Util
- Defined in:
- lib/translatomatic/provider/base.rb
Overview
This class is abstract.
Base class for interfaces to translation APIs
Instance Attribute Summary collapse
-
#listener ⇒ Object
Listener for translation events.
Class Method Summary collapse
-
.supports_alternative_translations? ⇒ boolean
True if a string can have alternative translations.
-
.supports_no_translate_html? ⇒ boolean
True if this provider supports html5 <span translate=“no”></span> tags.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Base
constructor
A new instance of Base.
-
#languages ⇒ Array<String>
A list of languages supported by this provider.
-
#name ⇒ String
The name of this provider.
-
#to_s ⇒ String
The name of this provider.
-
#translate(strings, from, to) ⇒ Array<Translatomatic::Translation::Result>
Translate strings from one locale to another.
Constructor Details
#initialize(options = {}) ⇒ Base
Returns a new instance of Base.
22 23 24 |
# File 'lib/translatomatic/provider/base.rb', line 22 def initialize( = {}) @listener = [:listener] end |
Instance Attribute Details
#listener ⇒ Object
Listener for translation events
9 10 11 |
# File 'lib/translatomatic/provider/base.rb', line 9 def listener @listener end |
Class Method Details
.supports_alternative_translations? ⇒ boolean
Returns True if a string can have alternative translations.
12 13 14 |
# File 'lib/translatomatic/provider/base.rb', line 12 def self.supports_alternative_translations? false end |
.supports_no_translate_html? ⇒ boolean
Returns true if this provider supports html5 <span translate=“no”></span> tags.
18 19 20 |
# File 'lib/translatomatic/provider/base.rb', line 18 def self.supports_no_translate_html? false end |
Instance Method Details
#languages ⇒ Array<String>
Returns A list of languages supported by this provider.
38 39 40 |
# File 'lib/translatomatic/provider/base.rb', line 38 def languages [] end |
#name ⇒ String
Returns The name of this provider.
27 28 29 |
# File 'lib/translatomatic/provider/base.rb', line 27 def name self.class.name.demodulize end |
#to_s ⇒ String
Returns The name of this provider.
32 33 34 |
# File 'lib/translatomatic/provider/base.rb', line 32 def to_s name end |
#translate(strings, from, to) ⇒ Array<Translatomatic::Translation::Result>
Translate strings from one locale to another
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/translatomatic/provider/base.rb', line 48 def translate(strings, from, to) @updated_listener = false @translations = [] @from = from @to = to strings = [strings] unless strings.is_a?(Array) from = build_locale(from) to = build_locale(to) if from.language == to.language strings.each { |i| add_translations(i, i) } else perform_translate(strings, from, to) end @translations end |