# frozen_string_literal: true # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # Auto-generated by gapic-generator-ruby. DO NOT EDIT! require "google/cloud/errors" require "google/cloud/translate/v3/translation_service_pb" module Google module Cloud module Translate module V3 module TranslationService ## # Client for the TranslationService service. # # Provides natural language translation operations. # class Client include Paths # @private attr_reader :translation_service_stub ## # Configure the TranslationService Client class. # # See {::Google::Cloud::Translate::V3::TranslationService::Client::Configuration} # for a description of the configuration fields. # # @example # # # Modify the configuration for all TranslationService clients # ::Google::Cloud::Translate::V3::TranslationService::Client.configure do |config| # config.timeout = 10.0 # end # # @yield [config] Configure the Client client. # @yieldparam config [Client::Configuration] # # @return [Client::Configuration] # def self.configure @configure ||= begin namespace = ["Google", "Cloud", "Translate", "V3"] parent_config = while namespace.any? parent_name = namespace.join "::" parent_const = const_get parent_name break parent_const.configure if parent_const.respond_to? :configure namespace.pop end default_config = Client::Configuration.new parent_config default_config.rpcs.translate_text.timeout = 600.0 default_config.rpcs.detect_language.timeout = 600.0 default_config.rpcs.get_supported_languages.timeout = 600.0 default_config.rpcs.get_supported_languages.retry_policy = { initial_delay: 0.1, max_delay: 60.0, multiplier: 1.3, retry_codes: [4, 14] } default_config.rpcs.translate_document.timeout = 600.0 default_config.rpcs.batch_translate_text.timeout = 600.0 default_config.rpcs.batch_translate_document.timeout = 600.0 default_config.rpcs.create_glossary.timeout = 600.0 default_config.rpcs.list_glossaries.timeout = 600.0 default_config.rpcs.list_glossaries.retry_policy = { initial_delay: 0.1, max_delay: 60.0, multiplier: 1.3, retry_codes: [4, 14] } default_config.rpcs.get_glossary.timeout = 600.0 default_config.rpcs.get_glossary.retry_policy = { initial_delay: 0.1, max_delay: 60.0, multiplier: 1.3, retry_codes: [4, 14] } default_config.rpcs.delete_glossary.timeout = 600.0 default_config.rpcs.delete_glossary.retry_policy = { initial_delay: 0.1, max_delay: 60.0, multiplier: 1.3, retry_codes: [4, 14] } default_config end yield @configure if block_given? @configure end ## # 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 {::Google::Cloud::Translate::V3::TranslationService::Client::Configuration} # for a description of the configuration fields. # # @yield [config] Configure the Client client. # @yieldparam config [Client::Configuration] # # @return [Client::Configuration] # def configure yield @config if block_given? @config end ## # Create a new TranslationService client object. # # @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 # # @yield [config] Configure the TranslationService client. # @yieldparam config [Client::Configuration] # def initialize # These require statements are intentionally placed here to initialize # the gRPC module only when it's required. # See https://github.com/googleapis/toolkit/issues/446 require "gapic/grpc" require "google/cloud/translate/v3/translation_service_services_pb" # Create the configuration object @config = Configuration.new Client.configure # Yield the configuration if needed yield @config if block_given? # Create credentials credentials = @config.credentials # Use self-signed JWT if the endpoint is unchanged from default, # but only if the default endpoint does not have a region prefix. enable_self_signed_jwt = @config.endpoint == Configuration::DEFAULT_ENDPOINT && !@config.endpoint.split(".").first.include?("-") credentials ||= Credentials.default scope: @config.scope, enable_self_signed_jwt: enable_self_signed_jwt if credentials.is_a?(::String) || credentials.is_a?(::Hash) credentials = Credentials.new credentials, scope: @config.scope end @quota_project_id = @config.quota_project @quota_project_id ||= credentials.quota_project_id if credentials.respond_to? :quota_project_id @operations_client = Operations.new do |config| config.credentials = credentials config.quota_project = @quota_project_id config.endpoint = @config.endpoint end @translation_service_stub = ::Gapic::ServiceStub.new( ::Google::Cloud::Translate::V3::TranslationService::Stub, credentials: credentials, endpoint: @config.endpoint, channel_args: @config.channel_args, interceptors: @config.interceptors ) end ## # Get the associated client for long-running operations. # # @return [::Google::Cloud::Translate::V3::TranslationService::Operations] # attr_reader :operations_client # Service calls ## # Translates input text and returns translated text. # # @overload translate_text(request, options = nil) # Pass arguments to `translate_text` via a request object, either of type # {::Google::Cloud::Translate::V3::TranslateTextRequest} or an equivalent Hash. # # @param 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. # @param options [::Gapic::CallOptions, ::Hash] # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional. # # @overload translate_text(contents: nil, mime_type: nil, source_language_code: nil, target_language_code: nil, parent: nil, model: nil, glossary_config: nil, labels: nil) # 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). # # @param 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. # @param 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". # @param 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. # @param 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. # @param 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. # @param 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 # @param 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. # @param 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. # # @yield [response, operation] Access the result along with the RPC operation # @yieldparam response [::Google::Cloud::Translate::V3::TranslateTextResponse] # @yieldparam operation [::GRPC::ActiveCall::Operation] # # @return [::Google::Cloud::Translate::V3::TranslateTextResponse] # # @raise [::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 # def translate_text request, options = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Translate::V3::TranslateTextRequest # Converts hash and nil to an options object options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults metadata = @config.rpcs.translate_text.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Translate::V3::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = {} if request.parent header_params["parent"] = request.parent end request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.translate_text.timeout, metadata: metadata, retry_policy: @config.rpcs.translate_text.retry_policy options.apply_defaults timeout: @config.timeout, metadata: @config.metadata, retry_policy: @config.retry_policy @translation_service_stub.call_rpc :translate_text, request, options: options do |response, operation| yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end ## # Detects the language of text within a request. # # @overload detect_language(request, options = nil) # Pass arguments to `detect_language` via a request object, either of type # {::Google::Cloud::Translate::V3::DetectLanguageRequest} or an equivalent Hash. # # @param 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. # @param options [::Gapic::CallOptions, ::Hash] # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional. # # @overload detect_language(parent: nil, model: nil, content: nil, mime_type: nil, labels: nil) # 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). # # @param 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. # @param 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. # @param content [::String] # The content of the input stored as a string. # @param 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". # @param 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. # # @yield [response, operation] Access the result along with the RPC operation # @yieldparam response [::Google::Cloud::Translate::V3::DetectLanguageResponse] # @yieldparam operation [::GRPC::ActiveCall::Operation] # # @return [::Google::Cloud::Translate::V3::DetectLanguageResponse] # # @raise [::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 # def detect_language request, options = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Translate::V3::DetectLanguageRequest # Converts hash and nil to an options object options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults metadata = @config.rpcs.detect_language.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Translate::V3::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = {} if request.parent header_params["parent"] = request.parent end request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.detect_language.timeout, metadata: metadata, retry_policy: @config.rpcs.detect_language.retry_policy options.apply_defaults timeout: @config.timeout, metadata: @config.metadata, retry_policy: @config.retry_policy @translation_service_stub.call_rpc :detect_language, request, options: options do |response, operation| yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end ## # Returns a list of supported languages for translation. # # @overload get_supported_languages(request, options = nil) # Pass arguments to `get_supported_languages` via a request object, either of type # {::Google::Cloud::Translate::V3::GetSupportedLanguagesRequest} or an equivalent Hash. # # @param 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. # @param options [::Gapic::CallOptions, ::Hash] # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional. # # @overload get_supported_languages(parent: nil, display_language_code: nil, model: nil) # 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). # # @param 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. # @param 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. # @param 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. # # @yield [response, operation] Access the result along with the RPC operation # @yieldparam response [::Google::Cloud::Translate::V3::SupportedLanguages] # @yieldparam operation [::GRPC::ActiveCall::Operation] # # @return [::Google::Cloud::Translate::V3::SupportedLanguages] # # @raise [::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 # def get_supported_languages request, options = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Translate::V3::GetSupportedLanguagesRequest # Converts hash and nil to an options object options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults metadata = @config.rpcs.get_supported_languages.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Translate::V3::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = {} if request.parent header_params["parent"] = request.parent end request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.get_supported_languages.timeout, metadata: metadata, retry_policy: @config.rpcs.get_supported_languages.retry_policy options.apply_defaults timeout: @config.timeout, metadata: @config.metadata, retry_policy: @config.retry_policy @translation_service_stub.call_rpc :get_supported_languages, request, options: options do |response, operation| yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end ## # Translates documents in synchronous mode. # # @overload translate_document(request, options = nil) # Pass arguments to `translate_document` via a request object, either of type # {::Google::Cloud::Translate::V3::TranslateDocumentRequest} or an equivalent Hash. # # @param 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. # @param options [::Gapic::CallOptions, ::Hash] # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional. # # @overload 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, enable_rotation_correction: nil) # 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). # # @param 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. # @param 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. # @param 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. # @param document_input_config [::Google::Cloud::Translate::V3::DocumentInputConfig, ::Hash] # Required. Input configurations. # @param 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. # @param 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. # @param 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. # @param 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. # @param 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 # @param is_translate_native_pdf_only [::Boolean] # Optional. is_translate_native_pdf_only field for external customers. # If true, the page limit of online native pdf translation is 300 and only # native pdf pages will be translated. # @param enable_shadow_removal_native_pdf [::Boolean] # Optional. If true, use the text removal server 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: false && pdf_native_only: false # @param enable_rotation_correction [::Boolean] # Optional. If true, enable auto rotation correction in DVS. # # @yield [response, operation] Access the result along with the RPC operation # @yieldparam response [::Google::Cloud::Translate::V3::TranslateDocumentResponse] # @yieldparam operation [::GRPC::ActiveCall::Operation] # # @return [::Google::Cloud::Translate::V3::TranslateDocumentResponse] # # @raise [::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 # def translate_document request, options = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Translate::V3::TranslateDocumentRequest # Converts hash and nil to an options object options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults metadata = @config.rpcs.translate_document.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Translate::V3::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = {} if request.parent header_params["parent"] = request.parent end request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.translate_document.timeout, metadata: metadata, retry_policy: @config.rpcs.translate_document.retry_policy options.apply_defaults timeout: @config.timeout, metadata: @config.metadata, retry_policy: @config.retry_policy @translation_service_stub.call_rpc :translate_document, request, options: options do |response, operation| yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end ## # 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. # # @overload batch_translate_text(request, options = nil) # Pass arguments to `batch_translate_text` via a request object, either of type # {::Google::Cloud::Translate::V3::BatchTranslateTextRequest} or an equivalent Hash. # # @param 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. # @param options [::Gapic::CallOptions, ::Hash] # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional. # # @overload 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) # 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). # # @param 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. # @param source_language_code [::String] # Required. Source language code. # @param target_language_codes [::Array<::String>] # Required. Specify up to 10 language codes here. # @param 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. # @param 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. # @param 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. # @param glossaries [::Hash{::String => ::Google::Cloud::Translate::V3::TranslateTextGlossaryConfig, ::Hash}] # Optional. Glossaries to be applied for translation. # It's keyed by target language code. # @param 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. # # @yield [response, operation] Access the result along with the RPC operation # @yieldparam response [::Gapic::Operation] # @yieldparam operation [::GRPC::ActiveCall::Operation] # # @return [::Gapic::Operation] # # @raise [::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 # def batch_translate_text request, options = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Translate::V3::BatchTranslateTextRequest # Converts hash and nil to an options object options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults metadata = @config.rpcs.batch_translate_text.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Translate::V3::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = {} if request.parent header_params["parent"] = request.parent end request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.batch_translate_text.timeout, metadata: metadata, retry_policy: @config.rpcs.batch_translate_text.retry_policy options.apply_defaults timeout: @config.timeout, metadata: @config.metadata, retry_policy: @config.retry_policy @translation_service_stub.call_rpc :batch_translate_text, request, options: options do |response, operation| response = ::Gapic::Operation.new response, @operations_client, options: options yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end ## # 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. # # @overload batch_translate_document(request, options = nil) # Pass arguments to `batch_translate_document` via a request object, either of type # {::Google::Cloud::Translate::V3::BatchTranslateDocumentRequest} or an equivalent Hash. # # @param 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. # @param options [::Gapic::CallOptions, ::Hash] # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional. # # @overload 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, enable_shadow_removal_native_pdf: nil, enable_rotation_correction: nil) # 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). # # @param 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. # @param 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](https://cloud.google.com/translate/docs/languages). # @param 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. # @param 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. # @param 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. # @param 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. # @param glossaries [::Hash{::String => ::Google::Cloud::Translate::V3::TranslateTextGlossaryConfig, ::Hash}] # Optional. Glossaries to be applied. It's keyed by target language code. # @param 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. # @param 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 # @param enable_shadow_removal_native_pdf [::Boolean] # Optional. If true, use the text removal server 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: false && pdf_native_only: false # @param enable_rotation_correction [::Boolean] # Optional. If true, enable auto rotation correction in DVS. # # @yield [response, operation] Access the result along with the RPC operation # @yieldparam response [::Gapic::Operation] # @yieldparam operation [::GRPC::ActiveCall::Operation] # # @return [::Gapic::Operation] # # @raise [::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 # def batch_translate_document request, options = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Translate::V3::BatchTranslateDocumentRequest # Converts hash and nil to an options object options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults metadata = @config.rpcs.batch_translate_document.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Translate::V3::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = {} if request.parent header_params["parent"] = request.parent end request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.batch_translate_document.timeout, metadata: metadata, retry_policy: @config.rpcs.batch_translate_document.retry_policy options.apply_defaults timeout: @config.timeout, metadata: @config.metadata, retry_policy: @config.retry_policy @translation_service_stub.call_rpc :batch_translate_document, request, options: options do |response, operation| response = ::Gapic::Operation.new response, @operations_client, options: options yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end ## # Creates a glossary and returns the long-running operation. Returns # NOT_FOUND, if the project doesn't exist. # # @overload create_glossary(request, options = nil) # Pass arguments to `create_glossary` via a request object, either of type # {::Google::Cloud::Translate::V3::CreateGlossaryRequest} or an equivalent Hash. # # @param 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. # @param options [::Gapic::CallOptions, ::Hash] # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional. # # @overload create_glossary(parent: nil, glossary: nil) # 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). # # @param parent [::String] # Required. The project name. # @param glossary [::Google::Cloud::Translate::V3::Glossary, ::Hash] # Required. The glossary to create. # # @yield [response, operation] Access the result along with the RPC operation # @yieldparam response [::Gapic::Operation] # @yieldparam operation [::GRPC::ActiveCall::Operation] # # @return [::Gapic::Operation] # # @raise [::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 # def create_glossary request, options = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Translate::V3::CreateGlossaryRequest # Converts hash and nil to an options object options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults metadata = @config.rpcs.create_glossary.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Translate::V3::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = {} if request.parent header_params["parent"] = request.parent end request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.create_glossary.timeout, metadata: metadata, retry_policy: @config.rpcs.create_glossary.retry_policy options.apply_defaults timeout: @config.timeout, metadata: @config.metadata, retry_policy: @config.retry_policy @translation_service_stub.call_rpc :create_glossary, request, options: options do |response, operation| response = ::Gapic::Operation.new response, @operations_client, options: options yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end ## # Lists glossaries in a project. Returns NOT_FOUND, if the project doesn't # exist. # # @overload list_glossaries(request, options = nil) # Pass arguments to `list_glossaries` via a request object, either of type # {::Google::Cloud::Translate::V3::ListGlossariesRequest} or an equivalent Hash. # # @param 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. # @param options [::Gapic::CallOptions, ::Hash] # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional. # # @overload list_glossaries(parent: nil, page_size: nil, page_token: nil, filter: nil) # 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). # # @param parent [::String] # Required. The name of the project from which to list all of the glossaries. # @param page_size [::Integer] # Optional. Requested page size. The server may return fewer glossaries than # requested. If unspecified, the server picks an appropriate default. # @param 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_token`is empty or missing. # @param 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. # # @yield [response, operation] Access the result along with the RPC operation # @yieldparam response [::Gapic::PagedEnumerable<::Google::Cloud::Translate::V3::Glossary>] # @yieldparam operation [::GRPC::ActiveCall::Operation] # # @return [::Gapic::PagedEnumerable<::Google::Cloud::Translate::V3::Glossary>] # # @raise [::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 # def list_glossaries request, options = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Translate::V3::ListGlossariesRequest # Converts hash and nil to an options object options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults metadata = @config.rpcs.list_glossaries.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Translate::V3::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = {} if request.parent header_params["parent"] = request.parent end request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.list_glossaries.timeout, metadata: metadata, retry_policy: @config.rpcs.list_glossaries.retry_policy options.apply_defaults timeout: @config.timeout, metadata: @config.metadata, retry_policy: @config.retry_policy @translation_service_stub.call_rpc :list_glossaries, request, options: options do |response, operation| response = ::Gapic::PagedEnumerable.new @translation_service_stub, :list_glossaries, request, response, operation, options yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end ## # Gets a glossary. Returns NOT_FOUND, if the glossary doesn't # exist. # # @overload get_glossary(request, options = nil) # Pass arguments to `get_glossary` via a request object, either of type # {::Google::Cloud::Translate::V3::GetGlossaryRequest} or an equivalent Hash. # # @param 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. # @param options [::Gapic::CallOptions, ::Hash] # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional. # # @overload get_glossary(name: nil) # 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). # # @param name [::String] # Required. The name of the glossary to retrieve. # # @yield [response, operation] Access the result along with the RPC operation # @yieldparam response [::Google::Cloud::Translate::V3::Glossary] # @yieldparam operation [::GRPC::ActiveCall::Operation] # # @return [::Google::Cloud::Translate::V3::Glossary] # # @raise [::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 # def get_glossary request, options = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Translate::V3::GetGlossaryRequest # Converts hash and nil to an options object options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults metadata = @config.rpcs.get_glossary.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Translate::V3::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = {} if request.name header_params["name"] = request.name end request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.get_glossary.timeout, metadata: metadata, retry_policy: @config.rpcs.get_glossary.retry_policy options.apply_defaults timeout: @config.timeout, metadata: @config.metadata, retry_policy: @config.retry_policy @translation_service_stub.call_rpc :get_glossary, request, options: options do |response, operation| yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end ## # Deletes a glossary, or cancels glossary construction # if the glossary isn't created yet. # Returns NOT_FOUND, if the glossary doesn't exist. # # @overload delete_glossary(request, options = nil) # Pass arguments to `delete_glossary` via a request object, either of type # {::Google::Cloud::Translate::V3::DeleteGlossaryRequest} or an equivalent Hash. # # @param 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. # @param options [::Gapic::CallOptions, ::Hash] # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional. # # @overload delete_glossary(name: nil) # 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). # # @param name [::String] # Required. The name of the glossary to delete. # # @yield [response, operation] Access the result along with the RPC operation # @yieldparam response [::Gapic::Operation] # @yieldparam operation [::GRPC::ActiveCall::Operation] # # @return [::Gapic::Operation] # # @raise [::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 # def delete_glossary request, options = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Translate::V3::DeleteGlossaryRequest # Converts hash and nil to an options object options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h # Customize the options with defaults metadata = @config.rpcs.delete_glossary.metadata.to_h # Set x-goog-api-client and x-goog-user-project headers metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Translate::V3::VERSION metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = {} if request.name header_params["name"] = request.name end request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") metadata[:"x-goog-request-params"] ||= request_params_header options.apply_defaults timeout: @config.rpcs.delete_glossary.timeout, metadata: metadata, retry_policy: @config.rpcs.delete_glossary.retry_policy options.apply_defaults timeout: @config.timeout, metadata: @config.metadata, retry_policy: @config.retry_policy @translation_service_stub.call_rpc :delete_glossary, request, options: options do |response, operation| response = ::Gapic::Operation.new response, @operations_client, options: options yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end ## # Configuration class for the TranslationService API. # # This class represents the configuration for TranslationService, # providing control over timeouts, retry behavior, logging, transport # parameters, and other low-level controls. Certain parameters can also be # applied individually to specific RPCs. See # {::Google::Cloud::Translate::V3::TranslationService::Client::Configuration::Rpcs} # for a list of RPCs that can be configured independently. # # Configuration can be applied globally to all clients, or to a single client # on construction. # # @example # # # Modify the global config, setting the timeout for # # translate_text to 20 seconds, # # and all remaining timeouts to 10 seconds. # ::Google::Cloud::Translate::V3::TranslationService::Client.configure do |config| # config.timeout = 10.0 # config.rpcs.translate_text.timeout = 20.0 # end # # # Apply the above configuration only to a new client. # client = ::Google::Cloud::Translate::V3::TranslationService::Client.new do |config| # config.timeout = 10.0 # config.rpcs.translate_text.timeout = 20.0 # end # # @!attribute [rw] endpoint # The hostname or hostname:port of the service endpoint. # Defaults to `"translate.googleapis.com"`. # @return [::String] # @!attribute [rw] credentials # Credentials to send with calls. You may provide any of the following types: # * (`String`) The path to a service account key file in JSON format # * (`Hash`) A service account key as a Hash # * (`Google::Auth::Credentials`) A googleauth credentials object # (see the [googleauth docs](https://rubydoc.info/gems/googleauth/Google/Auth/Credentials)) # * (`Signet::OAuth2::Client`) A signet oauth2 client object # (see the [signet docs](https://rubydoc.info/gems/signet/Signet/OAuth2/Client)) # * (`GRPC::Core::Channel`) a gRPC channel with included credentials # * (`GRPC::Core::ChannelCredentials`) a gRPC credentails object # * (`nil`) indicating no credentials # @return [::Object] # @!attribute [rw] scope # The OAuth scopes # @return [::Array<::String>] # @!attribute [rw] lib_name # The library name as recorded in instrumentation and logging # @return [::String] # @!attribute [rw] lib_version # The library version as recorded in instrumentation and logging # @return [::String] # @!attribute [rw] channel_args # Extra parameters passed to the gRPC channel. Note: this is ignored if a # `GRPC::Core::Channel` object is provided as the credential. # @return [::Hash] # @!attribute [rw] interceptors # An array of interceptors that are run before calls are executed. # @return [::Array<::GRPC::ClientInterceptor>] # @!attribute [rw] timeout # The call timeout in seconds. # @return [::Numeric] # @!attribute [rw] metadata # Additional gRPC headers to be sent with the call. # @return [::Hash{::Symbol=>::String}] # @!attribute [rw] retry_policy # The retry policy. The value is a hash with the following keys: # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds. # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds. # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier. # * `:retry_codes` (*type:* `Array`) - The error codes that should # trigger a retry. # @return [::Hash] # @!attribute [rw] quota_project # A separate project against which to charge quota. # @return [::String] # class Configuration extend ::Gapic::Config DEFAULT_ENDPOINT = "translate.googleapis.com" config_attr :endpoint, DEFAULT_ENDPOINT, ::String config_attr :credentials, nil do |value| allowed = [::String, ::Hash, ::Proc, ::Symbol, ::Google::Auth::Credentials, ::Signet::OAuth2::Client, nil] allowed += [::GRPC::Core::Channel, ::GRPC::Core::ChannelCredentials] if defined? ::GRPC allowed.any? { |klass| klass === value } end config_attr :scope, nil, ::String, ::Array, nil config_attr :lib_name, nil, ::String, nil config_attr :lib_version, nil, ::String, nil config_attr(:channel_args, { "grpc.service_config_disable_resolution" => 1 }, ::Hash, nil) config_attr :interceptors, nil, ::Array, nil config_attr :timeout, nil, ::Numeric, nil config_attr :metadata, nil, ::Hash, nil config_attr :retry_policy, nil, ::Hash, ::Proc, nil config_attr :quota_project, nil, ::String, nil # @private def initialize parent_config = nil @parent_config = parent_config unless parent_config.nil? yield self if block_given? end ## # Configurations for individual RPCs # @return [Rpcs] # def rpcs @rpcs ||= begin parent_rpcs = nil parent_rpcs = @parent_config.rpcs if defined?(@parent_config) && @parent_config.respond_to?(:rpcs) Rpcs.new parent_rpcs end end ## # Configuration RPC class for the TranslationService API. # # Includes fields providing the configuration for each RPC in this service. # Each configuration object is of type `Gapic::Config::Method` and includes # the following configuration fields: # # * `timeout` (*type:* `Numeric`) - The call timeout in seconds # * `metadata` (*type:* `Hash{Symbol=>String}`) - Additional gRPC headers # * `retry_policy (*type:* `Hash`) - The retry policy. The policy fields # include the following keys: # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds. # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds. # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier. # * `:retry_codes` (*type:* `Array`) - The error codes that should # trigger a retry. # class Rpcs ## # RPC-specific configuration for `translate_text` # @return [::Gapic::Config::Method] # attr_reader :translate_text ## # RPC-specific configuration for `detect_language` # @return [::Gapic::Config::Method] # attr_reader :detect_language ## # RPC-specific configuration for `get_supported_languages` # @return [::Gapic::Config::Method] # attr_reader :get_supported_languages ## # RPC-specific configuration for `translate_document` # @return [::Gapic::Config::Method] # attr_reader :translate_document ## # RPC-specific configuration for `batch_translate_text` # @return [::Gapic::Config::Method] # attr_reader :batch_translate_text ## # RPC-specific configuration for `batch_translate_document` # @return [::Gapic::Config::Method] # attr_reader :batch_translate_document ## # RPC-specific configuration for `create_glossary` # @return [::Gapic::Config::Method] # attr_reader :create_glossary ## # RPC-specific configuration for `list_glossaries` # @return [::Gapic::Config::Method] # attr_reader :list_glossaries ## # RPC-specific configuration for `get_glossary` # @return [::Gapic::Config::Method] # attr_reader :get_glossary ## # RPC-specific configuration for `delete_glossary` # @return [::Gapic::Config::Method] # attr_reader :delete_glossary # @private def initialize parent_rpcs = nil translate_text_config = parent_rpcs.translate_text if parent_rpcs.respond_to? :translate_text @translate_text = ::Gapic::Config::Method.new translate_text_config detect_language_config = parent_rpcs.detect_language if parent_rpcs.respond_to? :detect_language @detect_language = ::Gapic::Config::Method.new detect_language_config get_supported_languages_config = parent_rpcs.get_supported_languages if parent_rpcs.respond_to? :get_supported_languages @get_supported_languages = ::Gapic::Config::Method.new get_supported_languages_config translate_document_config = parent_rpcs.translate_document if parent_rpcs.respond_to? :translate_document @translate_document = ::Gapic::Config::Method.new translate_document_config batch_translate_text_config = parent_rpcs.batch_translate_text if parent_rpcs.respond_to? :batch_translate_text @batch_translate_text = ::Gapic::Config::Method.new batch_translate_text_config batch_translate_document_config = parent_rpcs.batch_translate_document if parent_rpcs.respond_to? :batch_translate_document @batch_translate_document = ::Gapic::Config::Method.new batch_translate_document_config create_glossary_config = parent_rpcs.create_glossary if parent_rpcs.respond_to? :create_glossary @create_glossary = ::Gapic::Config::Method.new create_glossary_config list_glossaries_config = parent_rpcs.list_glossaries if parent_rpcs.respond_to? :list_glossaries @list_glossaries = ::Gapic::Config::Method.new list_glossaries_config get_glossary_config = parent_rpcs.get_glossary if parent_rpcs.respond_to? :get_glossary @get_glossary = ::Gapic::Config::Method.new get_glossary_config delete_glossary_config = parent_rpcs.delete_glossary if parent_rpcs.respond_to? :delete_glossary @delete_glossary = ::Gapic::Config::Method.new delete_glossary_config yield self if block_given? end end end end end end end end end