Class: Google::Apis::TranslateV2::TranslateService

Inherits:
Core::BaseService show all
Defined in:
generated/google/apis/translate_v2/service.rb

Overview

Google Cloud Translation API

The Google Cloud Translation API lets websites and programs integrate with Google Translate programmatically.

Examples:

require 'google/apis/translate_v2'

Translate = Google::Apis::TranslateV2 # Alias the module
service = Translate::TranslateService.new

See Also:

Instance Attribute Summary collapse

Attributes inherited from Core::BaseService

#authorization, #base_path, #batch_path, #client, #client_options, #request_options, #root_url, #upload_path

Instance Method Summary collapse

Methods inherited from Core::BaseService

#batch, #batch_upload, #fetch_all, #http

Methods included from Core::Logging

#logger

Constructor Details

#initializeTranslateService

Returns a new instance of TranslateService



47
48
49
50
# File 'generated/google/apis/translate_v2/service.rb', line 47

def initialize
  super('https://translation.googleapis.com/', 'language/translate/')
  @batch_path = 'batch/translate'
end

Instance Attribute Details

#keyString

Returns API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.

Returns:

  • (String)

    API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.



39
40
41
# File 'generated/google/apis/translate_v2/service.rb', line 39

def key
  @key
end

#quota_userString

Returns Available to use for quota purposes for server-side applications. Can be any arbitrary string assigned to a user, but should not exceed 40 characters. Overrides userIp if both are provided.

Returns:

  • (String)

    Available to use for quota purposes for server-side applications. Can be any arbitrary string assigned to a user, but should not exceed 40 characters. Overrides userIp if both are provided.



45
46
47
# File 'generated/google/apis/translate_v2/service.rb', line 45

def quota_user
  @quota_user
end

Instance Method Details

#detect_detection_language(detect_language_request_object = nil, quota_user: nil, fields: nil, options: nil) {|result, err| ... } ⇒ Google::Apis::TranslateV2::ListDetectionsResponse

Detects the language of text within a request.

Parameters:

  • detect_language_request_object (Google::Apis::TranslateV2::DetectLanguageRequest) (defaults to: nil)
  • quota_user (String)

    Available to use for quota purposes for server-side applications. Can be any arbitrary string assigned to a user, but should not exceed 40 characters. Overrides userIp if both are provided.

  • fields (String)

    Selector specifying which fields to include in a partial response.

  • options (Google::Apis::RequestOptions)

    Request-specific options

Yields:

  • (result, err)

    Result & error if block supplied

Yield Parameters:

Returns:

Raises:



216
217
218
219
220
221
222
223
224
225
# File 'generated/google/apis/translate_v2/service.rb', line 216

def detect_detection_language(detect_language_request_object = nil, quota_user: nil, fields: nil, options: nil, &block)
  command =  make_simple_command(:post, 'v2/detect', options)
  command.request_representation = Google::Apis::TranslateV2::DetectLanguageRequest::Representation
  command.request_object = detect_language_request_object
  command.response_representation = Google::Apis::TranslateV2::ListDetectionsResponse::Representation
  command.response_class = Google::Apis::TranslateV2::ListDetectionsResponse
  command.query['quotaUser'] = quota_user unless quota_user.nil?
  command.query['fields'] = fields unless fields.nil?
  execute_or_queue_command(command, &block)
end

#list_detections(q, quota_user: nil, fields: nil, options: nil) {|result, err| ... } ⇒ Google::Apis::TranslateV2::ListDetectionsResponse

Detects the language of text within a request.

Parameters:

  • q (Array<String>, String)

    The input text upon which to perform language detection. Repeat this parameter to perform language detection on multiple text inputs.

  • quota_user (String)

    Available to use for quota purposes for server-side applications. Can be any arbitrary string assigned to a user, but should not exceed 40 characters. Overrides userIp if both are provided.

  • fields (String)

    Selector specifying which fields to include in a partial response.

  • options (Google::Apis::RequestOptions)

    Request-specific options

Yields:

  • (result, err)

    Result & error if block supplied

Yield Parameters:

Returns:

Raises:



186
187
188
189
190
191
192
193
194
# File 'generated/google/apis/translate_v2/service.rb', line 186

def list_detections(q, quota_user: nil, fields: nil, options: nil, &block)
  command =  make_simple_command(:get, 'v2/detect', options)
  command.response_representation = Google::Apis::TranslateV2::ListDetectionsResponse::Representation
  command.response_class = Google::Apis::TranslateV2::ListDetectionsResponse
  command.query['q'] = q unless q.nil?
  command.query['quotaUser'] = quota_user unless quota_user.nil?
  command.query['fields'] = fields unless fields.nil?
  execute_or_queue_command(command, &block)
end

#list_languages(target: nil, quota_user: nil, fields: nil, options: nil) {|result, err| ... } ⇒ Google::Apis::TranslateV2::ListLanguagesResponse

Returns a list of supported languages for translation.

Parameters:

  • target (String)

    The language to use to return localized, human readable names of supported languages.

  • quota_user (String)

    Available to use for quota purposes for server-side applications. Can be any arbitrary string assigned to a user, but should not exceed 40 characters. Overrides userIp if both are provided.

  • fields (String)

    Selector specifying which fields to include in a partial response.

  • options (Google::Apis::RequestOptions)

    Request-specific options

Yields:

  • (result, err)

    Result & error if block supplied

Yield Parameters:

Returns:

Raises:



74
75
76
77
78
79
80
81
82
# File 'generated/google/apis/translate_v2/service.rb', line 74

def list_languages(target: nil, quota_user: nil, fields: nil, options: nil, &block)
  command =  make_simple_command(:get, 'v2/languages', options)
  command.response_representation = Google::Apis::TranslateV2::ListLanguagesResponse::Representation
  command.response_class = Google::Apis::TranslateV2::ListLanguagesResponse
  command.query['target'] = target unless target.nil?
  command.query['quotaUser'] = quota_user unless quota_user.nil?
  command.query['fields'] = fields unless fields.nil?
  execute_or_queue_command(command, &block)
end

#list_translations(q, target, format: nil, source: nil, cid: nil, quota_user: nil, fields: nil, options: nil) {|result, err| ... } ⇒ Google::Apis::TranslateV2::ListTranslationsResponse

Translates input text, returning translated text.

Parameters:

  • q (Array<String>, String)

    The input text to translate. Repeat this parameter to perform translation operations on multiple text inputs.

  • target (String)

    The language to use for translation of the input text, set to one of the language codes listed in Language Support.

  • format (String)

    The format of the source text, in either HTML (default) or plain-text. A value of "html" indicates HTML and a value of "text" indicates plain-text.

  • source (String)

    The language of the source text, set to one of the language codes listed in Language Support. If the source language is not specified, the API will attempt to identify the source language automatically and return it within the response.

  • cid (Array<String>, String)

    The customization id for translate

  • quota_user (String)

    Available to use for quota purposes for server-side applications. Can be any arbitrary string assigned to a user, but should not exceed 40 characters. Overrides userIp if both are provided.

  • fields (String)

    Selector specifying which fields to include in a partial response.

  • options (Google::Apis::RequestOptions)

    Request-specific options

Yields:

  • (result, err)

    Result & error if block supplied

Yield Parameters:

Returns:

Raises:



119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'generated/google/apis/translate_v2/service.rb', line 119

def list_translations(q, target, format: nil, source: nil, cid: nil, quota_user: nil, fields: nil, options: nil, &block)
  command =  make_simple_command(:get, 'v2', options)
  command.response_representation = Google::Apis::TranslateV2::ListTranslationsResponse::Representation
  command.response_class = Google::Apis::TranslateV2::ListTranslationsResponse
  command.query['format'] = format unless format.nil?
  command.query['q'] = q unless q.nil?
  command.query['source'] = source unless source.nil?
  command.query['cid'] = cid unless cid.nil?
  command.query['target'] = target unless target.nil?
  command.query['quotaUser'] = quota_user unless quota_user.nil?
  command.query['fields'] = fields unless fields.nil?
  execute_or_queue_command(command, &block)
end

#translate_translation_text(translate_text_request_object = nil, quota_user: nil, fields: nil, options: nil) {|result, err| ... } ⇒ Google::Apis::TranslateV2::ListTranslationsResponse

Translates input text, returning translated text.

Parameters:

  • translate_text_request_object (Google::Apis::TranslateV2::TranslateTextRequest) (defaults to: nil)
  • quota_user (String)

    Available to use for quota purposes for server-side applications. Can be any arbitrary string assigned to a user, but should not exceed 40 characters. Overrides userIp if both are provided.

  • fields (String)

    Selector specifying which fields to include in a partial response.

  • options (Google::Apis::RequestOptions)

    Request-specific options

Yields:

  • (result, err)

    Result & error if block supplied

Yield Parameters:

Returns:

Raises:



153
154
155
156
157
158
159
160
161
162
# File 'generated/google/apis/translate_v2/service.rb', line 153

def translate_translation_text(translate_text_request_object = nil, quota_user: nil, fields: nil, options: nil, &block)
  command =  make_simple_command(:post, 'v2', options)
  command.request_representation = Google::Apis::TranslateV2::TranslateTextRequest::Representation
  command.request_object = translate_text_request_object
  command.response_representation = Google::Apis::TranslateV2::ListTranslationsResponse::Representation
  command.response_class = Google::Apis::TranslateV2::ListTranslationsResponse
  command.query['quotaUser'] = quota_user unless quota_user.nil?
  command.query['fields'] = fields unless fields.nil?
  execute_or_queue_command(command, &block)
end