Class: ABBYY::Cloud::Namespaces::MachineTranslations

Inherits:
Base
  • Object
show all
Defined in:
lib/abbyy/cloud/namespaces/machine_translations.rb

Overview

Namespace for operations with machine translations

Instance Method Summary collapse

Instance Method Details

#default_engineABBYY::Cloud::Models::Engine

Returns engine object for the default engine



22
23
24
# File 'lib/abbyy/cloud/namespaces/machine_translations.rb', line 22

def default_engine
  engine(settings.engine)
end

#engine(name) ⇒ ABBYY::Cloud::Models::Engine

Returns engine object selected by its name



16
17
18
# File 'lib/abbyy/cloud/namespaces/machine_translations.rb', line 16

def engine(name)
  engines.find { |engine| engine.name == name }
end

#enginesArray<ABBYY::Cloud::Models::Engine>

Returns list of all available engines

Returns:



10
11
12
# File 'lib/abbyy/cloud/namespaces/machine_translations.rb', line 10

def engines
  Operations::Engines.new(settings).call
end

#translate(text, from:, to:, **opts) ⇒ ABBYY::Cloud::Models::Translation

Instantly (synchronously) translates the text

Examples:

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

Parameters:

  • text (String)
  • [ABBYY::Cloud::Types::Locale] (Hash)

    a customizable set of options

Returns:



36
37
38
39
40
41
42
# 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) ⇒ ABBYY::Cloud::Models::Translation

Instantly (synchronously) translates array of texts

Examples:

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

Parameters:

  • texts (Array<String>)
  • [ABBYY::Cloud::Types::Locale] (Hash)

    a customizable set of options

Returns:



54
55
56
57
58
59
60
# 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