Class: Google::Cloud::Translate::V2::Api
- Inherits:
-
Object
- Object
- Google::Cloud::Translate::V2::Api
- Defined in:
- lib/google/cloud/translate/v2/api.rb
Overview
Api
Represents top-level access to the Google Cloud Translation API. Translation API supports more than one hundred different languages, from Afrikaans to Zulu. Used in combination, this enables translation between thousands of language pairs. Also, you can send in HTML and receive HTML with translated text back. You don't need to extract your source text or reassemble the translated content.
Instance Method Summary collapse
-
#detect(*text) ⇒ Detection+
Detect the most likely language or languages of a text or multiple texts.
-
#languages(language = nil) ⇒ Array<Language>
List the languages supported by the API.
-
#project_id ⇒ Object
(also: #project)
The Cloud Translation API project connected to.
-
#translate(*text, to: nil, from: nil, format: nil, model: nil, cid: nil) ⇒ Translation+
Returns text translations from one language to another.
Instance Method Details
#detect(*text) ⇒ Detection+
Detect the most likely language or languages of a text or multiple texts.
205 206 207 208 209 210 |
# File 'lib/google/cloud/translate/v2/api.rb', line 205 def detect *text return nil if text.empty? text = Array(text).flatten gapi = service.detect text Detection.from_gapi gapi, text end |
#languages(language = nil) ⇒ Array<Language>
List the languages supported by the API. These are the languages to and from which text can be translated.
245 246 247 248 249 |
# File 'lib/google/cloud/translate/v2/api.rb', line 245 def languages language = nil language = language.to_s if language gapi = service.languages language Array(gapi["languages"]).map { |g| Language.from_gapi g } end |
#project_id ⇒ Object Also known as: project
The Cloud Translation API project connected to.
75 76 77 |
# File 'lib/google/cloud/translate/v2/api.rb', line 75 def project_id service.project_id end |
#translate(*text, to: nil, from: nil, format: nil, model: nil, cid: nil) ⇒ Translation+
Returns text translations from one language to another.
162 163 164 165 166 167 168 169 170 171 |
# File 'lib/google/cloud/translate/v2/api.rb', line 162 def translate *text, to: nil, from: nil, format: nil, model: nil, cid: nil return nil if text.empty? raise ArgumentError, "to is required" if to.nil? to = to.to_s from = from.to_s if from format = format.to_s if format text = Array(text).flatten gapi = service.translate text, to: to, from: from, format: format, model: model, cid: cid Translation.from_gapi_list gapi, text, to, from end |