Module: Translatomatic::Translator
- Extended by:
- Util
- Defined in:
- lib/translatomatic/translator.rb,
lib/translatomatic/translator/base.rb,
lib/translatomatic/translator/google.rb,
lib/translatomatic/translator/yandex.rb,
lib/translatomatic/translator/frengly.rb,
lib/translatomatic/translator/microsoft.rb,
lib/translatomatic/translator/my_memory.rb
Defined Under Namespace
Classes: Base, Frengly, Google, Microsoft, MyMemory, Yandex
Class Method Summary collapse
-
.available(options = {}) ⇒ Array<#translate>
Find all configured translators.
-
.find(name) ⇒ Class
The translator class corresponding to the given name.
-
.list ⇒ String
A description of all translators and options.
-
.modules ⇒ List<Class>
A list of all translator classes.
-
.names ⇒ List<String>
A list of all translators.
Methods included from Util
Class Method Details
.available(options = {}) ⇒ Array<#translate>
Find all configured translators
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/translatomatic/translator.rb', line 34 def self.available( = {}) available = [] modules.each do |mod| begin translator = mod.new() available << translator rescue Exception log.debug("translator #{mod.name.demodulize} is unavailable") end end available end |
.find(name) ⇒ Class
Returns The translator class corresponding to the given name.
15 16 17 |
# File 'lib/translatomatic/translator.rb', line 15 def self.find(name) name ? self.const_get(name) : nil end |
.list ⇒ String
Returns A description of all translators and options.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/translatomatic/translator.rb', line 48 def self.list out = "Translators:\n" modules.each do |mod| out += "\n" + mod.name.demodulize + ":\n" opts = mod. opts.each do |opt| optname = opt.name.to_s.gsub("_", "-") out += " --%-18s %18s %10s %15s\n" % [optname, opt.description, opt.required ? "(required)" : "", opt.use_env ? "ENV[#{opt.name.upcase}]" : ""] end end out + "\n" end |
.modules ⇒ List<Class>
Returns A list of all translator classes.
20 21 22 23 24 |
# File 'lib/translatomatic/translator.rb', line 20 def self.modules self.constants.collect { |c| self.const_get(c) }.select do |klass| klass.is_a?(Class) && klass != Translatomatic::Translator::Base end end |
.names ⇒ List<String>
Returns A list of all translators.
27 28 29 |
# File 'lib/translatomatic/translator.rb', line 27 def self.names modules.collect { |i| i.name.demodulize } end |