Class: Google::Cloud::Translate::V3::TranslationService::Client

Inherits:
Object
  • Object
show all
Includes:
Paths
Defined in:
lib/google/cloud/translate/v3/translation_service/client.rb

Overview

Client for the TranslationService service.

Provides natural language translation operations.

Defined Under Namespace

Classes: Configuration

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Paths

#glossary_path, #location_path

Constructor Details

#initialize {|config| ... } ⇒ Client

Create a new TranslationService client object.

Examples

To create a new TranslationService client with the default configuration:

client = ::Google::Cloud::Translate::V3::TranslationService::Client.new

To create a new TranslationService client with a custom configuration:

client = ::Google::Cloud::Translate::V3::TranslationService::Client.new do |config|
  config.timeout = 10.0
end

Yields:

  • (config)

    Configure the TranslationService client.

Yield Parameters:



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/google/cloud/translate/v3/translation_service/client.rb', line 154

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
  credentials ||= Credentials.default scope: @config.scope
  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.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

Instance Attribute Details

#operations_client::Google::Cloud::Translate::V3::TranslationService::Operations (readonly)

Get the associated client for long-running operations.



195
196
197
# File 'lib/google/cloud/translate/v3/translation_service/client.rb', line 195

def operations_client
  @operations_client
end

Class Method Details

.configure {|config| ... } ⇒ Client::Configuration

Configure the TranslationService Client class.

See Configuration for a description of the configuration fields.

Example

To modify the configuration for all TranslationService clients:

::Google::Cloud::Translate::V3::TranslationService::Client.configure do |config|
  config.timeout = 10.0
end

Yields:

  • (config)

    Configure the Client client.

Yield Parameters:

Returns:



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/google/cloud/translate/v3/translation_service/client.rb', line 57

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.batch_translate_text.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

Instance Method Details

#batch_translate_text(request, options = nil) ⇒ ::Gapic::Operation #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:

  • #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) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #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) (defaults to: nil)

      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) (defaults to: nil)

      Required. Source language code.

    • target_language_codes (::Array<::String>) (defaults to: nil)

      Required. Specify up to 10 language codes here.

    • models (::Hash{::String => ::String}) (defaults to: nil)

      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, projects/{project-number-or-id}/locations/{location-id}/models/general/base

      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>) (defaults to: nil)

      Required. Input configurations. The total number of files matched should be <= 1000. The total content size should be <= 100M Unicode codepoints. The files must use UTF-8 encoding.

    • output_config (::Google::Cloud::Translate::V3::OutputConfig, ::Hash) (defaults to: nil)

      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}) (defaults to: nil)

      Optional. Glossaries to be applied for translation. It's keyed by target language code.

    • labels (::Hash{::String => ::String}) (defaults to: nil)

      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/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.



607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
# File 'lib/google/cloud/translate/v3/translation_service/client.rb', line 607

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
   = @config.rpcs.batch_translate_text..to_h

  # Set x-goog-api-client and x-goog-user-project headers
  [:"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
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {
    "parent" => request.parent
  }
  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.batch_translate_text.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.batch_translate_text.retry_policy
  options.apply_defaults metadata:     @config.,
                         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

#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 configure.

See Configuration for a description of the configuration fields.

Yields:

  • (config)

    Configure the Client client.

Yield Parameters:

Returns:



129
130
131
132
# File 'lib/google/cloud/translate/v3/translation_service/client.rb', line 129

def configure
  yield @config if block_given?
  @config
end

#create_glossary(request, options = nil) ⇒ ::Gapic::Operation #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:

  • #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) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #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.



677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
# File 'lib/google/cloud/translate/v3/translation_service/client.rb', line 677

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
   = @config.rpcs.create_glossary..to_h

  # Set x-goog-api-client and x-goog-user-project headers
  [:"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
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {
    "parent" => request.parent
  }
  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.create_glossary.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.create_glossary.retry_policy
  options.apply_defaults metadata:     @config.,
                         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

#delete_glossary(request, options = nil) ⇒ ::Gapic::Operation #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:

  • #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) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #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).

    Parameters:

    • name (::String) (defaults to: nil)

      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.



893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
# File 'lib/google/cloud/translate/v3/translation_service/client.rb', line 893

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
   = @config.rpcs.delete_glossary..to_h

  # Set x-goog-api-client and x-goog-user-project headers
  [:"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
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {
    "name" => request.name
  }
  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.delete_glossary.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.delete_glossary.retry_policy
  options.apply_defaults metadata:     @config.,
                         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

#detect_language(request, options = nil) ⇒ ::Google::Cloud::Translate::V3::DetectLanguageResponse #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:

  • #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) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #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) (defaults to: nil)

      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) (defaults to: nil)

      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) (defaults to: nil)

      The content of the input stored as a string.

    • mime_type (::String) (defaults to: nil)

      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}) (defaults to: nil)

      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/labels for more information.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (::Google::Cloud::Error)

    if the RPC is aborted.



388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
# File 'lib/google/cloud/translate/v3/translation_service/client.rb', line 388

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
   = @config.rpcs.detect_language..to_h

  # Set x-goog-api-client and x-goog-user-project headers
  [:"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
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {
    "parent" => request.parent
  }
  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.detect_language.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.detect_language.retry_policy
  options.apply_defaults metadata:     @config.,
                         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

#get_glossary(request, options = nil) ⇒ ::Google::Cloud::Translate::V3::Glossary #get_glossary(name: nil) ⇒ ::Google::Cloud::Translate::V3::Glossary

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

Overloads:

  • #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) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #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).

    Parameters:

    • name (::String) (defaults to: nil)

      Required. The name of the glossary to retrieve.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (::Google::Cloud::Error)

    if the RPC is aborted.



825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
# File 'lib/google/cloud/translate/v3/translation_service/client.rb', line 825

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
   = @config.rpcs.get_glossary..to_h

  # Set x-goog-api-client and x-goog-user-project headers
  [:"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
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {
    "name" => request.name
  }
  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.get_glossary.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.get_glossary.retry_policy
  options.apply_defaults metadata:     @config.,
                         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

#get_supported_languages(request, options = nil) ⇒ ::Google::Cloud::Translate::V3::SupportedLanguages #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:

  • #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) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #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) (defaults to: nil)

      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) (defaults to: nil)

      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) (defaults to: nil)

      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, projects/{project-number-or-id}/locations/{location-id}/models/general/base

      Returns languages supported by the specified model. If missing, we get supported languages of Google general base (PBMT) model.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (::Google::Cloud::Error)

    if the RPC is aborted.



485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
# File 'lib/google/cloud/translate/v3/translation_service/client.rb', line 485

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
   = @config.rpcs.get_supported_languages..to_h

  # Set x-goog-api-client and x-goog-user-project headers
  [:"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
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {
    "parent" => request.parent
  }
  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.get_supported_languages.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.get_supported_languages.retry_policy
  options.apply_defaults metadata:     @config.,
                         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

#list_glossaries(request, options = nil) ⇒ ::Gapic::PagedEnumerable<::Google::Cloud::Translate::V3::Glossary> #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:

  • #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) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #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) (defaults to: nil)

      Required. The name of the project from which to list all of the glossaries.

    • page_size (::Integer) (defaults to: nil)

      Optional. Requested page size. The server may return fewer glossaries than requested. If unspecified, the server picks an appropriate default.

    • page_token (::String) (defaults to: nil)

      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) (defaults to: nil)

      Optional. Filter specifying constraints of a list operation. Filtering is not supported yet, and the parameter currently has no effect. 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.



757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
# File 'lib/google/cloud/translate/v3/translation_service/client.rb', line 757

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
   = @config.rpcs.list_glossaries..to_h

  # Set x-goog-api-client and x-goog-user-project headers
  [:"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
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {
    "parent" => request.parent
  }
  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.list_glossaries.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.list_glossaries.retry_policy
  options.apply_defaults metadata:     @config.,
                         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

#translate_text(request, options = nil) ⇒ ::Google::Cloud::Translate::V3::TranslateTextResponse #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:

  • #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) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #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>) (defaults to: nil)

      Required. The content of the input in string format. We recommend the total content be less than 30k codepoints. Use BatchTranslateText for larger text.

    • mime_type (::String) (defaults to: nil)

      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) (defaults to: nil)

      Optional. The BCP-47 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) (defaults to: nil)

      Required. The BCP-47 language code to use for translation of the input text, set to one of the language codes listed in Language Support.

    • parent (::String) (defaults to: nil)

      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) (defaults to: nil)

      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, projects/{project-number-or-id}/locations/{location-id}/models/general/base

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

      If missing, the system decides which google base model to use.

    • glossary_config (::Google::Cloud::Translate::V3::TranslateTextGlossaryConfig, ::Hash) (defaults to: nil)

      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}) (defaults to: nil)

      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/labels for more information.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (::Google::Cloud::Error)

    if the RPC is aborted.



288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
# File 'lib/google/cloud/translate/v3/translation_service/client.rb', line 288

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
   = @config.rpcs.translate_text..to_h

  # Set x-goog-api-client and x-goog-user-project headers
  [:"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
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {
    "parent" => request.parent
  }
  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.translate_text.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.translate_text.retry_policy
  options.apply_defaults metadata:     @config.,
                         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