class Google::Cloud::Translate::V2::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
The source language from which the text was translated.
@return [String]
The target language into which the text was translated.
@return [String]
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]
The original query text that was translated.
@return [String]
The source language from which the text was translated.
@return [String]
The target language into which the text was translated.
@return [String]
The translated result.
@return [String]
The target language into which the text was translated.
@return [String]
The translated result.
@return [String]
The translated result.
@return [String]
Public Class Methods
@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
@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
@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
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