class ABBYY::Cloud::Namespaces::MachineTranslations

Namespace for operations with machine translations @see [api.abbyy.cloud/swagger/ui/index#!/MachineTranslation]

Public Instance Methods

default_engine() click to toggle source

Returns engine object for the default engine @return [ABBYY::Cloud::Models::Engine]

# File lib/abbyy/cloud/namespaces/machine_translations.rb, line 22
def default_engine
  engine(settings.engine)
end
engine(name) click to toggle source

Returns engine object selected by its name @return [ABBYY::Cloud::Models::Engine]

# File lib/abbyy/cloud/namespaces/machine_translations.rb, line 16
def engine(name)
  engines.find { |engine| engine.name == name }
end
engines() click to toggle source

Returns list of all available engines @return [Array<ABBYY::Cloud::Models::Engine>]

# File lib/abbyy/cloud/namespaces/machine_translations.rb, line 10
def engines
  Operations::Engines.new(settings).call
end
translate(text, from:, to:, **opts) click to toggle source

Instantly (synchronously) translates the text

@example

translate "Hello world!", from: "en", to: "fr_FR"

@param [String] text @option [ABBYY::Cloud::Types::Locale] :from Source language @option [ABBYY::Cloud::Types::Locale] :to Target language @return [ABBYY::Cloud::Models::Translation]

# File lib/abbyy/cloud/namespaces/machine_translations.rb, line 36
def translate(text, from:, to:, **opts)
  Operations::Translate.new(settings).call source_text:     text,
                                           source_language: from,
                                           target_language: to,
                                           engine: settings.engine,
                                           **opts
end
translate_segments(texts, from:, to:, **opts) click to toggle source

Instantly (synchronously) translates array of texts

@example

translate ["Hello", "world"], from: "en", to: "fr_FR"

@param [Array<String>] texts @option [ABBYY::Cloud::Types::Locale] :from Source language @option [ABBYY::Cloud::Types::Locale] :to Target language @return [ABBYY::Cloud::Models::Translation]

# File lib/abbyy/cloud/namespaces/machine_translations.rb, line 54
def translate_segments(texts, from:, to:, **opts)
  sources = texts.map { |text| { text: text } }
  Operations::TranslateSegments
    .new(settings)
    .call sources: sources, from: from, to: to, engine: settings.engine,
          **opts
end