Class: Translatomatic::Translator::Base Abstract

Inherits:
Object
  • Object
show all
Extended by:
DefineOptions
Includes:
Util
Defined in:
lib/translatomatic/translator/base.rb

Overview

This class is abstract.

Direct Known Subclasses

Frengly, Google, Microsoft, MyMemory, Yandex

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

#locale, #log, #string

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.



17
18
19
# File 'lib/translatomatic/translator/base.rb', line 17

def initialize(options = {})
  @listener = options[:listener]
end

Class Attribute Details

.optionsObject (readonly)

Returns the value of attribute options.



9
10
11
# File 'lib/translatomatic/translator/base.rb', line 9

def options
  @options
end

Instance Attribute Details

#listenerObject



15
16
17
# File 'lib/translatomatic/translator/base.rb', line 15

def listener
  @listener
end

Instance Method Details

#languagesArray<String>

Returns A list of languages supported by this translator.

Returns:

  • (Array<String>)

    A list of languages supported by this translator.



27
28
29
# File 'lib/translatomatic/translator/base.rb', line 27

def languages
  []
end

#nameString

Returns The name of this translator.

Returns:

  • (String)

    The name of this translator.



22
23
24
# File 'lib/translatomatic/translator/base.rb', line 22

def name
  self.class.name.demodulize
end

#translate(strings, from, to) ⇒ Array<String>

Translate strings from one locale to another

Parameters:

Returns:

  • (Array<String>)

    Translated strings



36
37
38
39
40
41
42
43
44
# File 'lib/translatomatic/translator/base.rb', line 36

def translate(strings, from, to)
  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