class Google::Cloud::Translate::V2::Translation

# Translation

Represents a translation query result. Returned by {Google::Cloud::Translate::V2::Api#translate}.

@see cloud.google.com/translation/docs/translating-text#Translate Translating Text

@example

require "google/cloud/translate/v2"

translate = Google::Cloud::Translate::V2.new

translation = translate.translate "Hello world!", to: "la"

translation.to_s #=> "Salve mundi!"

translation.from #=> "en"
translation.origin #=> "Hello world!"
translation.to #=> "la"
translation.text #=> "Salve mundi!"

Attributes

from[R]

The source language from which the text was translated.

@return [String]

language[R]

The target language into which the text was translated.

@return [String]

model[R]

The translation model. Can be either `base` for the Phrase-Based Machine Translation (PBMT) model, or `nmt` for the Neural Machine Translation (NMT) model. If you did not include a model parameter with your request, then this field is not included in the response.

@return [String]

origin[R]

The original query text that was translated.

@return [String]

source[R]

The source language from which the text was translated.

@return [String]

target[R]

The target language into which the text was translated.

@return [String]

text[R]

The translated result.

@return [String]

to[R]

The target language into which the text was translated.

@return [String]

to_s[R]

The translated result.

@return [String]

to_str[R]

The translated result.

@return [String]

Public Class Methods

from_gapi(gapi, to, origin, from) click to toggle source

@private New Translation from a TranslationsResource object as defined by the Google API Client object.

# File lib/google/cloud/translate/v2/translation.rb, line 111
def self.from_gapi gapi, to, origin, from
  from ||= gapi["detectedSourceLanguage"]
  detected = !gapi["detectedSourceLanguage"].nil?
  new gapi["translatedText"], to, origin, from, gapi["model"], detected
end
from_gapi_list(gapi, text, to, from) click to toggle source

@private New Translation from a TranslationsListResponse object as defined by the Google API Client object.

# File lib/google/cloud/translate/v2/translation.rb, line 101
def self.from_gapi_list gapi, text, to, from
  res = text.zip(Array(gapi["translations"])).map do |origin, g|
    from_gapi g, to, origin, from
  end
  return res.first if res.size == 1
  res
end
new(text, to, origin, from, model, detected) click to toggle source

@private Create a new object.

# File lib/google/cloud/translate/v2/translation.rb, line 81
def initialize text, to, origin, from, model, detected
  @text = text
  @to = to
  @origin = origin
  @from = from
  @model = model
  @detected = detected
end

Public Instance Methods

detected?() click to toggle source

Determines if the source language was detected by the Google Cloud Cloud Translation API.

@return [Boolean] `true` if the source language was detected by the Cloud Translation API, `false` if the

source language was provided in the request
# File lib/google/cloud/translate/v2/translation.rb, line 95
def detected?
  @detected
end