Cloud Translation V3 API - Class Google::Cloud::Translate::V3::TranslationService::Client (v0.7.3)

Reference documentation and code samples for the Cloud Translation V3 API class Google::Cloud::Translate::V3::TranslationService::Client.

Client for the TranslationService service.

Provides natural language translation operations.

Inherits

  • Object

Methods

.configure

def self.configure() { |config| ... } -> Client::Configuration

Configure the TranslationService Client class.

See Configuration for a description of the configuration fields.

Yields
  • (config) — Configure the Client client.
Yield Parameter
Example
# Modify the configuration for all TranslationService clients
::Google::Cloud::Translate::V3::TranslationService::Client.configure do |config|
  config.timeout = 10.0
end

#batch_translate_document

def batch_translate_document(request, options = nil) -> ::Gapic::Operation
def batch_translate_document(parent: nil, source_language_code: nil, target_language_codes: nil, input_configs: nil, output_config: nil, models: nil, glossaries: nil, format_conversions: nil, customized_attribution: nil) -> ::Gapic::Operation

Translates a large volume of document in asynchronous batch mode. This function provides real-time output as the inputs are being processed. If caller cancels a request, the partial results (for an input file, it's all or nothing) may still be available on the specified output location.

This call returns immediately and you can use google.longrunning.Operation.name to poll the status of the call.

Overloads
def batch_translate_document(request, options = nil) -> ::Gapic::Operation
Pass arguments to batch_translate_document via a request object, either of type BatchTranslateDocumentRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Translate::V3::BatchTranslateDocumentRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def batch_translate_document(parent: nil, source_language_code: nil, target_language_codes: nil, input_configs: nil, output_config: nil, models: nil, glossaries: nil, format_conversions: nil, customized_attribution: nil) -> ::Gapic::Operation
Pass arguments to batch_translate_document via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameters
  • parent (::String) — Required. Location to make a regional call.

    Format: projects/{project-number-or-id}/locations/{location-id}.

    The global location is not supported for batch translation.

    Only AutoML Translation models or glossaries within the same region (have the same location-id) can be used, otherwise an INVALID_ARGUMENT (400) error is returned.

  • source_language_code (::String) — Required. The ISO-639 language code of the input document if known, for example, "en-US" or "sr-Latn". Supported language codes are listed in Language Support.
  • target_language_codes (::Array<::String>) — Required. The ISO-639 language code to use for translation of the input document. Specify up to 10 language codes here.
  • input_configs (::Array<::Google::Cloud::Translate::V3::BatchDocumentInputConfig, ::Hash>) — Required. Input configurations. The total number of files matched should be <= 100. The total content size to translate should be <= 100M Unicode codepoints. The files must use UTF-8 encoding.
  • output_config (::Google::Cloud::Translate::V3::BatchDocumentOutputConfig, ::Hash) — Required. Output configuration. If 2 input configs match to the same file (that is, same input path), we don't generate output for duplicate inputs.
  • models (::Hash{::String => ::String}) — Optional. The models to use for translation. Map's key is target language code. Map's value is the model name. Value can be a built-in general model, or an AutoML Translation model.

    The value format depends on model type:

    • AutoML Translation models: projects/{project-number-or-id}/locations/{location-id}/models/{model-id}

    • General (built-in) models: projects/{project-number-or-id}/locations/{location-id}/models/general/nmt,

    If the map is empty or a specific model is not requested for a language pair, then default google model (nmt) is used.

  • glossaries (::Hash{::String => ::Google::Cloud::Translate::V3::TranslateTextGlossaryConfig, ::Hash}) — Optional. Glossaries to be applied. It's keyed by target language code.
  • format_conversions (::Hash{::String => ::String}) — Optional. File format conversion map to be applied to all input files. Map's key is the original mime_type. Map's value is the target mime_type of translated documents.

    Supported file format conversion includes:

    • application/pdf to application/vnd.openxmlformats-officedocument.wordprocessingml.document

    If nothing specified, output files will be in the same format as the original file.

  • customized_attribution (::String) — Optional. This flag is to support user customized attribution. If not provided, the default is Machine Translated by Google. Customized attribution should follow rules in https://cloud.google.com/translate/attribution#attribution_and_logos
Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
  • response (::Gapic::Operation)
  • operation (::GRPC::ActiveCall::Operation)
Returns
  • (::Gapic::Operation)
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/translate/v3"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Translate::V3::TranslationService::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Translate::V3::BatchTranslateDocumentRequest.new

# Call the batch_translate_document method.
result = client.batch_translate_document request

# The returned object is of type Gapic::Operation. You can use it to
# check the status of an operation, cancel it, or wait for results.
# Here is how to wait for a response.
result.wait_until_done! timeout: 60
if result.response?
  p result.response
else
  puts "No response received."
end

#batch_translate_text

def batch_translate_text(request, options = nil) -> ::Gapic::Operation
def batch_translate_text(parent: nil, source_language_code: nil, target_language_codes: nil, models: nil, input_configs: nil, output_config: nil, glossaries: nil, labels: nil) -> ::Gapic::Operation

Translates a large volume of text in asynchronous batch mode. This function provides real-time output as the inputs are being processed. If caller cancels a request, the partial results (for an input file, it's all or nothing) may still be available on the specified output location.

This call returns immediately and you can use google.longrunning.Operation.name to poll the status of the call.

Overloads
def batch_translate_text(request, options = nil) -> ::Gapic::Operation
Pass arguments to batch_translate_text via a request object, either of type BatchTranslateTextRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Translate::V3::BatchTranslateTextRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def batch_translate_text(parent: nil, source_language_code: nil, target_language_codes: nil, models: nil, input_configs: nil, output_config: nil, glossaries: nil, labels: nil) -> ::Gapic::Operation
Pass arguments to batch_translate_text via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameters
  • parent (::String) — Required. Location to make a call. Must refer to a caller's project.

    Format: projects/{project-number-or-id}/locations/{location-id}.

    The global location is not supported for batch translation.

    Only AutoML Translation models or glossaries within the same region (have the same location-id) can be used, otherwise an INVALID_ARGUMENT (400) error is returned.

  • source_language_code (::String) — Required. Source language code.
  • target_language_codes (::Array<::String>) — Required. Specify up to 10 language codes here.
  • models (::Hash{::String => ::String}) — Optional. The models to use for translation. Map's key is target language code. Map's value is model name. Value can be a built-in general model, or an AutoML Translation model.

    The value format depends on model type:

    • AutoML Translation models: projects/{project-number-or-id}/locations/{location-id}/models/{model-id}

    • General (built-in) models: projects/{project-number-or-id}/locations/{location-id}/models/general/nmt,

    If the map is empty or a specific model is not requested for a language pair, then default google model (nmt) is used.

  • input_configs (::Array<::Google::Cloud::Translate::V3::InputConfig, ::Hash>) — Required. Input configurations. The total number of files matched should be <= 100. The total content size should be <= 100M Unicode codepoints. The files must use UTF-8 encoding.
  • output_config (::Google::Cloud::Translate::V3::OutputConfig, ::Hash) — Required. Output configuration. If 2 input configs match to the same file (that is, same input path), we don't generate output for duplicate inputs.
  • glossaries (::Hash{::String => ::Google::Cloud::Translate::V3::TranslateTextGlossaryConfig, ::Hash}) — Optional. Glossaries to be applied for translation. It's keyed by target language code.
  • labels (::Hash{::String => ::String}) — Optional. The labels with user-defined metadata for the request.

    Label keys and values can be no longer than 63 characters (Unicode codepoints), can only contain lowercase letters, numeric characters, underscores and dashes. International characters are allowed. Label values are optional. Label keys must start with a letter.

    See https://cloud.google.com/translate/docs/advanced/labels for more information.

Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
  • response (::Gapic::Operation)
  • operation (::GRPC::ActiveCall::Operation)
Returns
  • (::Gapic::Operation)
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/translate/v3"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Translate::V3::TranslationService::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Translate::V3::BatchTranslateTextRequest.new

# Call the batch_translate_text method.
result = client.batch_translate_text request

# The returned object is of type Gapic::Operation. You can use it to
# check the status of an operation, cancel it, or wait for results.
# Here is how to wait for a response.
result.wait_until_done! timeout: 60
if result.response?
  p result.response
else
  puts "No response received."
end

#configure

def configure() { |config| ... } -> Client::Configuration

Configure the TranslationService Client instance.

The configuration is set to the derived mode, meaning that values can be changed, but structural changes (adding new fields, etc.) are not allowed. Structural changes should be made on Client.configure.

See Configuration for a description of the configuration fields.

Yields
  • (config) — Configure the Client client.
Yield Parameter

#create_glossary

def create_glossary(request, options = nil) -> ::Gapic::Operation
def create_glossary(parent: nil, glossary: nil) -> ::Gapic::Operation

Creates a glossary and returns the long-running operation. Returns NOT_FOUND, if the project doesn't exist.

Overloads
def create_glossary(request, options = nil) -> ::Gapic::Operation
Pass arguments to create_glossary via a request object, either of type CreateGlossaryRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Translate::V3::CreateGlossaryRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def create_glossary(parent: nil, glossary: nil) -> ::Gapic::Operation
Pass arguments to create_glossary via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameters
Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
  • response (::Gapic::Operation)
  • operation (::GRPC::ActiveCall::Operation)
Returns
  • (::Gapic::Operation)
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/translate/v3"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Translate::V3::TranslationService::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Translate::V3::CreateGlossaryRequest.new

# Call the create_glossary method.
result = client.create_glossary request

# The returned object is of type Gapic::Operation. You can use it to
# check the status of an operation, cancel it, or wait for results.
# Here is how to wait for a response.
result.wait_until_done! timeout: 60
if result.response?
  p result.response
else
  puts "No response received."
end

#delete_glossary

def delete_glossary(request, options = nil) -> ::Gapic::Operation
def delete_glossary(name: nil) -> ::Gapic::Operation

Deletes a glossary, or cancels glossary construction if the glossary isn't created yet. Returns NOT_FOUND, if the glossary doesn't exist.

Overloads
def delete_glossary(request, options = nil) -> ::Gapic::Operation
Pass arguments to delete_glossary via a request object, either of type DeleteGlossaryRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Translate::V3::DeleteGlossaryRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def delete_glossary(name: nil) -> ::Gapic::Operation
Pass arguments to delete_glossary via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameter
  • name (::String) — Required. The name of the glossary to delete.
Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
  • response (::Gapic::Operation)
  • operation (::GRPC::ActiveCall::Operation)
Returns
  • (::Gapic::Operation)
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/translate/v3"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Translate::V3::TranslationService::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Translate::V3::DeleteGlossaryRequest.new

# Call the delete_glossary method.
result = client.delete_glossary request

# The returned object is of type Gapic::Operation. You can use it to
# check the status of an operation, cancel it, or wait for results.
# Here is how to wait for a response.
result.wait_until_done! timeout: 60
if result.response?
  p result.response
else
  puts "No response received."
end

#detect_language

def detect_language(request, options = nil) -> ::Google::Cloud::Translate::V3::DetectLanguageResponse
def detect_language(parent: nil, model: nil, content: nil, mime_type: nil, labels: nil) -> ::Google::Cloud::Translate::V3::DetectLanguageResponse

Detects the language of text within a request.

Overloads
def detect_language(request, options = nil) -> ::Google::Cloud::Translate::V3::DetectLanguageResponse
Pass arguments to detect_language via a request object, either of type DetectLanguageRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Translate::V3::DetectLanguageRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def detect_language(parent: nil, model: nil, content: nil, mime_type: nil, labels: nil) -> ::Google::Cloud::Translate::V3::DetectLanguageResponse
Pass arguments to detect_language via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameters
  • parent (::String) — Required. Project or location to make a call. Must refer to a caller's project.

    Format: projects/{project-number-or-id}/locations/{location-id} or projects/{project-number-or-id}.

    For global calls, use projects/{project-number-or-id}/locations/global or projects/{project-number-or-id}.

    Only models within the same region (has same location-id) can be used. Otherwise an INVALID_ARGUMENT (400) error is returned.

  • model (::String) — Optional. The language detection model to be used.

    Format: projects/{project-number-or-id}/locations/{location-id}/models/language-detection/{model-id}

    Only one language detection model is currently supported: projects/{project-number-or-id}/locations/{location-id}/models/language-detection/default.

    If not specified, the default model is used.

  • content (::String) — The content of the input stored as a string.
  • mime_type (::String) — Optional. The format of the source text, for example, "text/html", "text/plain". If left blank, the MIME type defaults to "text/html".
  • labels (::Hash{::String => ::String}) — Optional. The labels with user-defined metadata for the request.

    Label keys and values can be no longer than 63 characters (Unicode codepoints), can only contain lowercase letters, numeric characters, underscores and dashes. International characters are allowed. Label values are optional. Label keys must start with a letter.

    See https://cloud.google.com/translate/docs/advanced/labels for more information.

Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/translate/v3"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Translate::V3::TranslationService::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Translate::V3::DetectLanguageRequest.new

# Call the detect_language method.
result = client.detect_language request

# The returned object is of type Google::Cloud::Translate::V3::DetectLanguageResponse.
p result

#get_glossary

def get_glossary(request, options = nil) -> ::Google::Cloud::Translate::V3::Glossary
def get_glossary(name: nil) -> ::Google::Cloud::Translate::V3::Glossary

Gets a glossary. Returns NOT_FOUND, if the glossary doesn't exist.

Overloads
def get_glossary(request, options = nil) -> ::Google::Cloud::Translate::V3::Glossary
Pass arguments to get_glossary via a request object, either of type GetGlossaryRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Translate::V3::GetGlossaryRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def get_glossary(name: nil) -> ::Google::Cloud::Translate::V3::Glossary
Pass arguments to get_glossary via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameter
  • name (::String) — Required. The name of the glossary to retrieve.
Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/translate/v3"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Translate::V3::TranslationService::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Translate::V3::GetGlossaryRequest.new

# Call the get_glossary method.
result = client.get_glossary request

# The returned object is of type Google::Cloud::Translate::V3::Glossary.
p result

#get_supported_languages

def get_supported_languages(request, options = nil) -> ::Google::Cloud::Translate::V3::SupportedLanguages
def get_supported_languages(parent: nil, display_language_code: nil, model: nil) -> ::Google::Cloud::Translate::V3::SupportedLanguages

Returns a list of supported languages for translation.

Overloads
def get_supported_languages(request, options = nil) -> ::Google::Cloud::Translate::V3::SupportedLanguages
Pass arguments to get_supported_languages via a request object, either of type GetSupportedLanguagesRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Translate::V3::GetSupportedLanguagesRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def get_supported_languages(parent: nil, display_language_code: nil, model: nil) -> ::Google::Cloud::Translate::V3::SupportedLanguages
Pass arguments to get_supported_languages via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameters
  • parent (::String) — Required. Project or location to make a call. Must refer to a caller's project.

    Format: projects/{project-number-or-id} or projects/{project-number-or-id}/locations/{location-id}.

    For global calls, use projects/{project-number-or-id}/locations/global or projects/{project-number-or-id}.

    Non-global location is required for AutoML models.

    Only models within the same region (have same location-id) can be used, otherwise an INVALID_ARGUMENT (400) error is returned.

  • display_language_code (::String) — Optional. The language to use to return localized, human readable names of supported languages. If missing, then display names are not returned in a response.
  • model (::String) — Optional. Get supported languages of this model.

    The format depends on model type:

    • AutoML Translation models: projects/{project-number-or-id}/locations/{location-id}/models/{model-id}

    • General (built-in) models: projects/{project-number-or-id}/locations/{location-id}/models/general/nmt,

    Returns languages supported by the specified model. If missing, we get supported languages of Google general NMT model.

Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/translate/v3"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Translate::V3::TranslationService::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Translate::V3::GetSupportedLanguagesRequest.new

# Call the get_supported_languages method.
result = client.get_supported_languages request

# The returned object is of type Google::Cloud::Translate::V3::SupportedLanguages.
p result

#initialize

def initialize() { |config| ... } -> Client

Create a new TranslationService client object.

Yields
  • (config) — Configure the TranslationService client.
Yield Parameter
Returns
  • (Client) — a new instance of Client
Example
# Create a client using the default configuration
client = ::Google::Cloud::Translate::V3::TranslationService::Client.new

# Create a client using a custom configuration
client = ::Google::Cloud::Translate::V3::TranslationService::Client.new do |config|
  config.timeout = 10.0
end

#list_glossaries

def list_glossaries(request, options = nil) -> ::Gapic::PagedEnumerable<::Google::Cloud::Translate::V3::Glossary>
def list_glossaries(parent: nil, page_size: nil, page_token: nil, filter: nil) -> ::Gapic::PagedEnumerable<::Google::Cloud::Translate::V3::Glossary>

Lists glossaries in a project. Returns NOT_FOUND, if the project doesn't exist.

Overloads
def list_glossaries(request, options = nil) -> ::Gapic::PagedEnumerable<::Google::Cloud::Translate::V3::Glossary>
Pass arguments to list_glossaries via a request object, either of type ListGlossariesRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Translate::V3::ListGlossariesRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def list_glossaries(parent: nil, page_size: nil, page_token: nil, filter: nil) -> ::Gapic::PagedEnumerable<::Google::Cloud::Translate::V3::Glossary>
Pass arguments to list_glossaries via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameters
  • parent (::String) — Required. The name of the project from which to list all of the glossaries.
  • page_size (::Integer) — Optional. Requested page size. The server may return fewer glossaries than requested. If unspecified, the server picks an appropriate default.
  • page_token (::String) — Optional. A token identifying a page of results the server should return. Typically, this is the value of [ListGlossariesResponse.next_page_token] returned from the previous call to ListGlossaries method. The first page is returned if page_tokenis empty or missing.
  • filter (::String) — Optional. Filter specifying constraints of a list operation. Specify the constraint by the format of "key=value", where key must be "src" or "tgt", and the value must be a valid language code. For multiple restrictions, concatenate them by "AND" (uppercase only), such as: "src=en-US AND tgt=zh-CN". Notice that the exact match is used here, which means using 'en-US' and 'en' can lead to different results, which depends on the language code you used when you create the glossary. For the unidirectional glossaries, the "src" and "tgt" add restrictions on the source and target language code separately. For the equivalent term set glossaries, the "src" and/or "tgt" add restrictions on the term set. For example: "src=en-US AND tgt=zh-CN" will only pick the unidirectional glossaries which exactly match the source language code as "en-US" and the target language code "zh-CN", but all equivalent term set glossaries which contain "en-US" and "zh-CN" in their language set will be picked. If missing, no filtering is performed.
Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Returns
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/translate/v3"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Translate::V3::TranslationService::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Translate::V3::ListGlossariesRequest.new

# Call the list_glossaries method.
result = client.list_glossaries request

# The returned object is of type Gapic::PagedEnumerable. You can iterate
# over elements, and API calls will be issued to fetch pages as needed.
result.each do |item|
  # Each element is of type ::Google::Cloud::Translate::V3::Glossary.
  p item
end

#operations_client

def operations_client() -> ::Google::Cloud::Translate::V3::TranslationService::Operations

Get the associated client for long-running operations.

#translate_document

def translate_document(request, options = nil) -> ::Google::Cloud::Translate::V3::TranslateDocumentResponse
def translate_document(parent: nil, source_language_code: nil, target_language_code: nil, document_input_config: nil, document_output_config: nil, model: nil, glossary_config: nil, labels: nil, customized_attribution: nil, is_translate_native_pdf_only: nil, enable_shadow_removal_native_pdf: nil) -> ::Google::Cloud::Translate::V3::TranslateDocumentResponse

Translates documents in synchronous mode.

Overloads
def translate_document(request, options = nil) -> ::Google::Cloud::Translate::V3::TranslateDocumentResponse
Pass arguments to translate_document via a request object, either of type Google::Cloud::Translate::V3::TranslateDocumentRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Translate::V3::TranslateDocumentRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def translate_document(parent: nil, source_language_code: nil, target_language_code: nil, document_input_config: nil, document_output_config: nil, model: nil, glossary_config: nil, labels: nil, customized_attribution: nil, is_translate_native_pdf_only: nil, enable_shadow_removal_native_pdf: nil) -> ::Google::Cloud::Translate::V3::TranslateDocumentResponse
Pass arguments to translate_document via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameters
  • parent (::String) — Required. Location to make a regional call.

    Format: projects/{project-number-or-id}/locations/{location-id}.

    For global calls, use projects/{project-number-or-id}/locations/global or projects/{project-number-or-id}.

    Non-global location is required for requests using AutoML models or custom glossaries.

    Models and glossaries must be within the same region (have the same location-id), otherwise an INVALID_ARGUMENT (400) error is returned.

  • source_language_code (::String) — Optional. The ISO-639 language code of the input document if known, for example, "en-US" or "sr-Latn". Supported language codes are listed in Language Support. If the source language isn't specified, the API attempts to identify the source language automatically and returns the source language within the response. Source language must be specified if the request contains a glossary or a custom model.
  • target_language_code (::String) — Required. The ISO-639 language code to use for translation of the input document, set to one of the language codes listed in Language Support.
  • document_input_config (::Google::Cloud::Translate::V3::DocumentInputConfig, ::Hash) — Required. Input configurations.
  • document_output_config (::Google::Cloud::Translate::V3::DocumentOutputConfig, ::Hash) — Optional. Output configurations. Defines if the output file should be stored within Cloud Storage as well as the desired output format. If not provided the translated file will only be returned through a byte-stream and its output mime type will be the same as the input file's mime type.
  • model (::String) — Optional. The model type requested for this translation.

    The format depends on model type:

    • AutoML Translation models: projects/{project-number-or-id}/locations/{location-id}/models/{model-id}

    • General (built-in) models: projects/{project-number-or-id}/locations/{location-id}/models/general/nmt,

    If not provided, the default Google model (NMT) will be used for translation.

  • glossary_config (::Google::Cloud::Translate::V3::TranslateTextGlossaryConfig, ::Hash) — Optional. Glossary to be applied. The glossary must be within the same region (have the same location-id) as the model, otherwise an INVALID_ARGUMENT (400) error is returned.
  • labels (::Hash{::String => ::String}) — Optional. The labels with user-defined metadata for the request.

    Label keys and values can be no longer than 63 characters (Unicode codepoints), can only contain lowercase letters, numeric characters, underscores and dashes. International characters are allowed. Label values are optional. Label keys must start with a letter.

    See https://cloud.google.com/translate/docs/advanced/labels for more information.

  • customized_attribution (::String) — Optional. This flag is to support user customized attribution. If not provided, the default is Machine Translated by Google. Customized attribution should follow rules in https://cloud.google.com/translate/attribution#attribution_and_logos
  • is_translate_native_pdf_only (::Boolean) — Optional. If true, the page limit of online native pdf translation is 300 and only native pdf pages will be translated.
  • enable_shadow_removal_native_pdf (::Boolean) — Optional. If true, use the text removal to remove the shadow text on background image for native pdf translation. Shadow removal feature can only be enabled when is_translate_native_pdf_only is false
Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/translate/v3"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Translate::V3::TranslationService::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Translate::V3::TranslateDocumentRequest.new

# Call the translate_document method.
result = client.translate_document request

# The returned object is of type Google::Cloud::Translate::V3::TranslateDocumentResponse.
p result

#translate_text

def translate_text(request, options = nil) -> ::Google::Cloud::Translate::V3::TranslateTextResponse
def translate_text(contents: nil, mime_type: nil, source_language_code: nil, target_language_code: nil, parent: nil, model: nil, glossary_config: nil, labels: nil) -> ::Google::Cloud::Translate::V3::TranslateTextResponse

Translates input text and returns translated text.

Overloads
def translate_text(request, options = nil) -> ::Google::Cloud::Translate::V3::TranslateTextResponse
Pass arguments to translate_text via a request object, either of type Google::Cloud::Translate::V3::TranslateTextRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Translate::V3::TranslateTextRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def translate_text(contents: nil, mime_type: nil, source_language_code: nil, target_language_code: nil, parent: nil, model: nil, glossary_config: nil, labels: nil) -> ::Google::Cloud::Translate::V3::TranslateTextResponse
Pass arguments to translate_text via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameters
  • contents (::Array<::String>) — Required. The content of the input in string format. We recommend the total content be less than 30,000 codepoints. The max length of this field is 1024. Use BatchTranslateText for larger text.
  • mime_type (::String) — Optional. The format of the source text, for example, "text/html", "text/plain". If left blank, the MIME type defaults to "text/html".
  • source_language_code (::String) — Optional. The ISO-639 language code of the input text if known, for example, "en-US" or "sr-Latn". Supported language codes are listed in Language Support. If the source language isn't specified, the API attempts to identify the source language automatically and returns the source language within the response.
  • target_language_code (::String) — Required. The ISO-639 language code to use for translation of the input text, set to one of the language codes listed in Language Support.
  • parent (::String) — Required. Project or location to make a call. Must refer to a caller's project.

    Format: projects/{project-number-or-id} or projects/{project-number-or-id}/locations/{location-id}.

    For global calls, use projects/{project-number-or-id}/locations/global or projects/{project-number-or-id}.

    Non-global location is required for requests using AutoML models or custom glossaries.

    Models and glossaries must be within the same region (have same location-id), otherwise an INVALID_ARGUMENT (400) error is returned.

  • model (::String) — Optional. The model type requested for this translation.

    The format depends on model type:

    • AutoML Translation models: projects/{project-number-or-id}/locations/{location-id}/models/{model-id}

    • General (built-in) models: projects/{project-number-or-id}/locations/{location-id}/models/general/nmt,

    For global (non-regionalized) requests, use location-id global. For example, projects/{project-number-or-id}/locations/global/models/general/nmt.

    If not provided, the default Google model (NMT) will be used.

  • glossary_config (::Google::Cloud::Translate::V3::TranslateTextGlossaryConfig, ::Hash) — Optional. Glossary to be applied. The glossary must be within the same region (have the same location-id) as the model, otherwise an INVALID_ARGUMENT (400) error is returned.
  • labels (::Hash{::String => ::String}) — Optional. The labels with user-defined metadata for the request.

    Label keys and values can be no longer than 63 characters (Unicode codepoints), can only contain lowercase letters, numeric characters, underscores and dashes. International characters are allowed. Label values are optional. Label keys must start with a letter.

    See https://cloud.google.com/translate/docs/advanced/labels for more information.

Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/translate/v3"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Translate::V3::TranslationService::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Translate::V3::TranslateTextRequest.new

# Call the translate_text method.
result = client.translate_text request

# The returned object is of type Google::Cloud::Translate::V3::TranslateTextResponse.
p result