google-cloud-translate-v3 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/AUTHENTICATION.md +8 -8
- data/README.md +1 -1
- data/lib/google/cloud/translate/v3/translation_service/client.rb +352 -70
- data/lib/google/cloud/translate/v3/translation_service/operations.rb +34 -25
- data/lib/google/cloud/translate/v3/translation_service_pb.rb +99 -0
- data/lib/google/cloud/translate/v3/translation_service_services_pb.rb +11 -2
- data/lib/google/cloud/translate/v3/version.rb +1 -1
- data/proto_docs/google/api/field_behavior.rb +7 -1
- data/proto_docs/google/cloud/translate/v3/translation_service.rb +559 -25
- metadata +13 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8cfa4d08984860e5959afa7256f8f0f080f06ab005fa1d4b9d0faf0c8eb4bf1
|
4
|
+
data.tar.gz: 352e5dca02bf816caa32be3aef72876ccbc730e5169bc4eb6927b8631421c911
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 488a8eb67f8215a8bdc46951ae63c0b0af83bcdfefde0125e3fcb7806c6208a50b85b9008c50a149a6737b8c6631102ee5bf61c2cb5e80341470c7ebca0657bf
|
7
|
+
data.tar.gz: ff5fab29974c8902d18bc8a17b5438fa4b098bfccb6b73eab04ae72ac2c62327ec5c208641908d6a8b03a630071238887afdd89008f77627f52f515071de573d
|
data/AUTHENTICATION.md
CHANGED
@@ -66,11 +66,11 @@ The environment variables that google-cloud-translate-v3
|
|
66
66
|
checks for credentials are configured on the service Credentials class (such as
|
67
67
|
{::Google::Cloud::Translate::V3::TranslationService::Credentials}):
|
68
68
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
69
|
+
* `TRANSLATE_CREDENTIALS` - Path to JSON file, or JSON contents
|
70
|
+
* `TRANSLATE_KEYFILE` - Path to JSON file, or JSON contents
|
71
|
+
* `GOOGLE_CLOUD_CREDENTIALS` - Path to JSON file, or JSON contents
|
72
|
+
* `GOOGLE_CLOUD_KEYFILE` - Path to JSON file, or JSON contents
|
73
|
+
* `GOOGLE_APPLICATION_CREDENTIALS` - Path to JSON file
|
74
74
|
|
75
75
|
```ruby
|
76
76
|
require "google/cloud/translate/v3"
|
@@ -82,8 +82,8 @@ client = ::Google::Cloud::Translate::V3::TranslationService::Client.new
|
|
82
82
|
|
83
83
|
### Configuration
|
84
84
|
|
85
|
-
The **Credentials JSON** can be configured instead of
|
86
|
-
environment
|
85
|
+
The path to the **Credentials JSON** file can be configured instead of storing
|
86
|
+
it in an environment variable. Either on an individual client initialization:
|
87
87
|
|
88
88
|
```ruby
|
89
89
|
require "google/cloud/translate/v3"
|
@@ -93,7 +93,7 @@ client = ::Google::Cloud::Translate::V3::TranslationService::Client.new do |conf
|
|
93
93
|
end
|
94
94
|
```
|
95
95
|
|
96
|
-
Or
|
96
|
+
Or globally for all clients:
|
97
97
|
|
98
98
|
```ruby
|
99
99
|
require "google/cloud/translate/v3"
|
data/README.md
CHANGED
@@ -33,7 +33,7 @@ In order to use this library, you first need to go through the following steps:
|
|
33
33
|
require "google/cloud/translate/v3"
|
34
34
|
|
35
35
|
client = ::Google::Cloud::Translate::V3::TranslationService::Client.new
|
36
|
-
request =
|
36
|
+
request = ::Google::Cloud::Translate::V3::TranslateTextRequest.new # (request fields as keyword arguments...)
|
37
37
|
response = client.translate_text request
|
38
38
|
```
|
39
39
|
|
@@ -41,13 +41,12 @@ module Google
|
|
41
41
|
# See {::Google::Cloud::Translate::V3::TranslationService::Client::Configuration}
|
42
42
|
# for a description of the configuration fields.
|
43
43
|
#
|
44
|
-
#
|
44
|
+
# @example
|
45
45
|
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
# end
|
46
|
+
# # Modify the configuration for all TranslationService clients
|
47
|
+
# ::Google::Cloud::Translate::V3::TranslationService::Client.configure do |config|
|
48
|
+
# config.timeout = 10.0
|
49
|
+
# end
|
51
50
|
#
|
52
51
|
# @yield [config] Configure the Client client.
|
53
52
|
# @yieldparam config [Client::Configuration]
|
@@ -71,38 +70,30 @@ module Google
|
|
71
70
|
|
72
71
|
default_config.rpcs.get_supported_languages.timeout = 600.0
|
73
72
|
default_config.rpcs.get_supported_languages.retry_policy = {
|
74
|
-
initial_delay: 0.1,
|
75
|
-
max_delay: 60.0,
|
76
|
-
multiplier: 1.3,
|
77
|
-
retry_codes: [4, 14]
|
73
|
+
initial_delay: 0.1, max_delay: 60.0, multiplier: 1.3, retry_codes: [4, 14]
|
78
74
|
}
|
79
75
|
|
76
|
+
default_config.rpcs.translate_document.timeout = 600.0
|
77
|
+
|
80
78
|
default_config.rpcs.batch_translate_text.timeout = 600.0
|
81
79
|
|
80
|
+
default_config.rpcs.batch_translate_document.timeout = 600.0
|
81
|
+
|
82
82
|
default_config.rpcs.create_glossary.timeout = 600.0
|
83
83
|
|
84
84
|
default_config.rpcs.list_glossaries.timeout = 600.0
|
85
85
|
default_config.rpcs.list_glossaries.retry_policy = {
|
86
|
-
initial_delay: 0.1,
|
87
|
-
max_delay: 60.0,
|
88
|
-
multiplier: 1.3,
|
89
|
-
retry_codes: [4, 14]
|
86
|
+
initial_delay: 0.1, max_delay: 60.0, multiplier: 1.3, retry_codes: [4, 14]
|
90
87
|
}
|
91
88
|
|
92
89
|
default_config.rpcs.get_glossary.timeout = 600.0
|
93
90
|
default_config.rpcs.get_glossary.retry_policy = {
|
94
|
-
initial_delay: 0.1,
|
95
|
-
max_delay: 60.0,
|
96
|
-
multiplier: 1.3,
|
97
|
-
retry_codes: [4, 14]
|
91
|
+
initial_delay: 0.1, max_delay: 60.0, multiplier: 1.3, retry_codes: [4, 14]
|
98
92
|
}
|
99
93
|
|
100
94
|
default_config.rpcs.delete_glossary.timeout = 600.0
|
101
95
|
default_config.rpcs.delete_glossary.retry_policy = {
|
102
|
-
initial_delay: 0.1,
|
103
|
-
max_delay: 60.0,
|
104
|
-
multiplier: 1.3,
|
105
|
-
retry_codes: [4, 14]
|
96
|
+
initial_delay: 0.1, max_delay: 60.0, multiplier: 1.3, retry_codes: [4, 14]
|
106
97
|
}
|
107
98
|
|
108
99
|
default_config
|
@@ -134,19 +125,15 @@ module Google
|
|
134
125
|
##
|
135
126
|
# Create a new TranslationService client object.
|
136
127
|
#
|
137
|
-
#
|
128
|
+
# @example
|
138
129
|
#
|
139
|
-
#
|
140
|
-
#
|
130
|
+
# # Create a client using the default configuration
|
131
|
+
# client = ::Google::Cloud::Translate::V3::TranslationService::Client.new
|
141
132
|
#
|
142
|
-
#
|
143
|
-
#
|
144
|
-
#
|
145
|
-
#
|
146
|
-
#
|
147
|
-
# client = ::Google::Cloud::Translate::V3::TranslationService::Client.new do |config|
|
148
|
-
# config.timeout = 10.0
|
149
|
-
# end
|
133
|
+
# # Create a client using a custom configuration
|
134
|
+
# client = ::Google::Cloud::Translate::V3::TranslationService::Client.new do |config|
|
135
|
+
# config.timeout = 10.0
|
136
|
+
# end
|
150
137
|
#
|
151
138
|
# @yield [config] Configure the TranslationService client.
|
152
139
|
# @yieldparam config [Client::Configuration]
|
@@ -166,14 +153,13 @@ module Google
|
|
166
153
|
|
167
154
|
# Create credentials
|
168
155
|
credentials = @config.credentials
|
169
|
-
# Use self-signed JWT if the
|
156
|
+
# Use self-signed JWT if the endpoint is unchanged from default,
|
170
157
|
# but only if the default endpoint does not have a region prefix.
|
171
|
-
enable_self_signed_jwt = @config.
|
172
|
-
@config.endpoint == Client.configure.endpoint &&
|
158
|
+
enable_self_signed_jwt = @config.endpoint == Client.configure.endpoint &&
|
173
159
|
!@config.endpoint.split(".").first.include?("-")
|
174
160
|
credentials ||= Credentials.default scope: @config.scope,
|
175
161
|
enable_self_signed_jwt: enable_self_signed_jwt
|
176
|
-
if credentials.is_a?(String) || credentials.is_a?(Hash)
|
162
|
+
if credentials.is_a?(::String) || credentials.is_a?(::Hash)
|
177
163
|
credentials = Credentials.new credentials, scope: @config.scope
|
178
164
|
end
|
179
165
|
@quota_project_id = @config.quota_project
|
@@ -222,7 +208,8 @@ module Google
|
|
222
208
|
#
|
223
209
|
# @param contents [::Array<::String>]
|
224
210
|
# Required. The content of the input in string format.
|
225
|
-
# We recommend the total content be less than 30k codepoints.
|
211
|
+
# We recommend the total content be less than 30k codepoints. The max length
|
212
|
+
# of this field is 1024.
|
226
213
|
# Use BatchTranslateText for larger text.
|
227
214
|
# @param mime_type [::String]
|
228
215
|
# Optional. The format of the source text, for example, "text/html",
|
@@ -261,14 +248,13 @@ module Google
|
|
261
248
|
#
|
262
249
|
# - General (built-in) models:
|
263
250
|
# `projects/{project-number-or-id}/locations/{location-id}/models/general/nmt`,
|
264
|
-
# `projects/{project-number-or-id}/locations/{location-id}/models/general/base`
|
265
251
|
#
|
266
252
|
#
|
267
253
|
# For global (non-regionalized) requests, use `location-id` `global`.
|
268
254
|
# For example,
|
269
255
|
# `projects/{project-number-or-id}/locations/global/models/general/nmt`.
|
270
256
|
#
|
271
|
-
# If
|
257
|
+
# If not provided, the default Google model (NMT) will be used.
|
272
258
|
# @param glossary_config [::Google::Cloud::Translate::V3::TranslateTextGlossaryConfig, ::Hash]
|
273
259
|
# Optional. Glossary to be applied. The glossary must be
|
274
260
|
# within the same region (have the same location-id) as the model, otherwise
|
@@ -281,7 +267,8 @@ module Google
|
|
281
267
|
# characters, underscores and dashes. International characters are allowed.
|
282
268
|
# Label values are optional. Label keys must start with a letter.
|
283
269
|
#
|
284
|
-
# See https://cloud.google.com/translate/docs/labels for more
|
270
|
+
# See https://cloud.google.com/translate/docs/advanced/labels for more
|
271
|
+
# information.
|
285
272
|
#
|
286
273
|
# @yield [response, operation] Access the result along with the RPC operation
|
287
274
|
# @yieldparam response [::Google::Cloud::Translate::V3::TranslateTextResponse]
|
@@ -317,7 +304,9 @@ module Google
|
|
317
304
|
options.apply_defaults timeout: @config.rpcs.translate_text.timeout,
|
318
305
|
metadata: metadata,
|
319
306
|
retry_policy: @config.rpcs.translate_text.retry_policy
|
320
|
-
|
307
|
+
|
308
|
+
options.apply_defaults timeout: @config.timeout,
|
309
|
+
metadata: @config.metadata,
|
321
310
|
retry_policy: @config.retry_policy
|
322
311
|
|
323
312
|
@translation_service_stub.call_rpc :translate_text, request, options: options do |response, operation|
|
@@ -381,7 +370,8 @@ module Google
|
|
381
370
|
# characters, underscores and dashes. International characters are allowed.
|
382
371
|
# Label values are optional. Label keys must start with a letter.
|
383
372
|
#
|
384
|
-
# See https://cloud.google.com/translate/docs/labels for more
|
373
|
+
# See https://cloud.google.com/translate/docs/advanced/labels for more
|
374
|
+
# information.
|
385
375
|
#
|
386
376
|
# @yield [response, operation] Access the result along with the RPC operation
|
387
377
|
# @yieldparam response [::Google::Cloud::Translate::V3::DetectLanguageResponse]
|
@@ -417,7 +407,9 @@ module Google
|
|
417
407
|
options.apply_defaults timeout: @config.rpcs.detect_language.timeout,
|
418
408
|
metadata: metadata,
|
419
409
|
retry_policy: @config.rpcs.detect_language.retry_policy
|
420
|
-
|
410
|
+
|
411
|
+
options.apply_defaults timeout: @config.timeout,
|
412
|
+
metadata: @config.metadata,
|
421
413
|
retry_policy: @config.retry_policy
|
422
414
|
|
423
415
|
@translation_service_stub.call_rpc :detect_language, request, options: options do |response, operation|
|
@@ -474,11 +466,10 @@ module Google
|
|
474
466
|
#
|
475
467
|
# - General (built-in) models:
|
476
468
|
# `projects/{project-number-or-id}/locations/{location-id}/models/general/nmt`,
|
477
|
-
# `projects/{project-number-or-id}/locations/{location-id}/models/general/base`
|
478
469
|
#
|
479
470
|
#
|
480
471
|
# Returns languages supported by the specified model.
|
481
|
-
# If missing, we get supported languages of Google general
|
472
|
+
# If missing, we get supported languages of Google general NMT model.
|
482
473
|
#
|
483
474
|
# @yield [response, operation] Access the result along with the RPC operation
|
484
475
|
# @yieldparam response [::Google::Cloud::Translate::V3::SupportedLanguages]
|
@@ -514,7 +505,9 @@ module Google
|
|
514
505
|
options.apply_defaults timeout: @config.rpcs.get_supported_languages.timeout,
|
515
506
|
metadata: metadata,
|
516
507
|
retry_policy: @config.rpcs.get_supported_languages.retry_policy
|
517
|
-
|
508
|
+
|
509
|
+
options.apply_defaults timeout: @config.timeout,
|
510
|
+
metadata: @config.metadata,
|
518
511
|
retry_policy: @config.retry_policy
|
519
512
|
|
520
513
|
@translation_service_stub.call_rpc :get_supported_languages, request, options: options do |response, operation|
|
@@ -525,6 +518,131 @@ module Google
|
|
525
518
|
raise ::Google::Cloud::Error.from_error(e)
|
526
519
|
end
|
527
520
|
|
521
|
+
##
|
522
|
+
# Translates documents in synchronous mode.
|
523
|
+
#
|
524
|
+
# @overload translate_document(request, options = nil)
|
525
|
+
# Pass arguments to `translate_document` via a request object, either of type
|
526
|
+
# {::Google::Cloud::Translate::V3::TranslateDocumentRequest} or an equivalent Hash.
|
527
|
+
#
|
528
|
+
# @param request [::Google::Cloud::Translate::V3::TranslateDocumentRequest, ::Hash]
|
529
|
+
# A request object representing the call parameters. Required. To specify no
|
530
|
+
# parameters, or to keep all the default parameter values, pass an empty Hash.
|
531
|
+
# @param options [::Gapic::CallOptions, ::Hash]
|
532
|
+
# Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
|
533
|
+
#
|
534
|
+
# @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)
|
535
|
+
# Pass arguments to `translate_document` via keyword arguments. Note that at
|
536
|
+
# least one keyword argument is required. To specify no parameters, or to keep all
|
537
|
+
# the default parameter values, pass an empty Hash as a request object (see above).
|
538
|
+
#
|
539
|
+
# @param parent [::String]
|
540
|
+
# Required. Location to make a regional call.
|
541
|
+
#
|
542
|
+
# Format: `projects/{project-number-or-id}/locations/{location-id}`.
|
543
|
+
#
|
544
|
+
# For global calls, use `projects/{project-number-or-id}/locations/global` or
|
545
|
+
# `projects/{project-number-or-id}`.
|
546
|
+
#
|
547
|
+
# Non-global location is required for requests using AutoML models or custom
|
548
|
+
# glossaries.
|
549
|
+
#
|
550
|
+
# Models and glossaries must be within the same region (have the same
|
551
|
+
# location-id), otherwise an INVALID_ARGUMENT (400) error is returned.
|
552
|
+
# @param source_language_code [::String]
|
553
|
+
# Optional. The BCP-47 language code of the input document if known, for
|
554
|
+
# example, "en-US" or "sr-Latn". Supported language codes are listed in
|
555
|
+
# Language Support. If the source language isn't specified, the API attempts
|
556
|
+
# to identify the source language automatically and returns the source
|
557
|
+
# language within the response. Source language must be specified if the
|
558
|
+
# request contains a glossary or a custom model.
|
559
|
+
# @param target_language_code [::String]
|
560
|
+
# Required. The BCP-47 language code to use for translation of the input
|
561
|
+
# document, set to one of the language codes listed in Language Support.
|
562
|
+
# @param document_input_config [::Google::Cloud::Translate::V3::DocumentInputConfig, ::Hash]
|
563
|
+
# Required. Input configurations.
|
564
|
+
# @param document_output_config [::Google::Cloud::Translate::V3::DocumentOutputConfig, ::Hash]
|
565
|
+
# Optional. Output configurations.
|
566
|
+
# Defines if the output file should be stored within Cloud Storage as well
|
567
|
+
# as the desired output format. If not provided the translated file will
|
568
|
+
# only be returned through a byte-stream and its output mime type will be
|
569
|
+
# the same as the input file's mime type.
|
570
|
+
# @param model [::String]
|
571
|
+
# Optional. The `model` type requested for this translation.
|
572
|
+
#
|
573
|
+
# The format depends on model type:
|
574
|
+
#
|
575
|
+
# - AutoML Translation models:
|
576
|
+
# `projects/{project-number-or-id}/locations/{location-id}/models/{model-id}`
|
577
|
+
#
|
578
|
+
# - General (built-in) models:
|
579
|
+
# `projects/{project-number-or-id}/locations/{location-id}/models/general/nmt`,
|
580
|
+
#
|
581
|
+
#
|
582
|
+
# If not provided, the default Google model (NMT) will be used for
|
583
|
+
# translation.
|
584
|
+
# @param glossary_config [::Google::Cloud::Translate::V3::TranslateTextGlossaryConfig, ::Hash]
|
585
|
+
# Optional. Glossary to be applied. The glossary must be within the same
|
586
|
+
# region (have the same location-id) as the model, otherwise an
|
587
|
+
# INVALID_ARGUMENT (400) error is returned.
|
588
|
+
# @param labels [::Hash{::String => ::String}]
|
589
|
+
# Optional. The labels with user-defined metadata for the request.
|
590
|
+
#
|
591
|
+
# Label keys and values can be no longer than 63 characters (Unicode
|
592
|
+
# codepoints), can only contain lowercase letters, numeric characters,
|
593
|
+
# underscores and dashes. International characters are allowed. Label values
|
594
|
+
# are optional. Label keys must start with a letter.
|
595
|
+
#
|
596
|
+
# See https://cloud.google.com/translate/docs/advanced/labels for more
|
597
|
+
# information.
|
598
|
+
#
|
599
|
+
# @yield [response, operation] Access the result along with the RPC operation
|
600
|
+
# @yieldparam response [::Google::Cloud::Translate::V3::TranslateDocumentResponse]
|
601
|
+
# @yieldparam operation [::GRPC::ActiveCall::Operation]
|
602
|
+
#
|
603
|
+
# @return [::Google::Cloud::Translate::V3::TranslateDocumentResponse]
|
604
|
+
#
|
605
|
+
# @raise [::Google::Cloud::Error] if the RPC is aborted.
|
606
|
+
#
|
607
|
+
def translate_document request, options = nil
|
608
|
+
raise ::ArgumentError, "request must be provided" if request.nil?
|
609
|
+
|
610
|
+
request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Translate::V3::TranslateDocumentRequest
|
611
|
+
|
612
|
+
# Converts hash and nil to an options object
|
613
|
+
options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
|
614
|
+
|
615
|
+
# Customize the options with defaults
|
616
|
+
metadata = @config.rpcs.translate_document.metadata.to_h
|
617
|
+
|
618
|
+
# Set x-goog-api-client and x-goog-user-project headers
|
619
|
+
metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
|
620
|
+
lib_name: @config.lib_name, lib_version: @config.lib_version,
|
621
|
+
gapic_version: ::Google::Cloud::Translate::V3::VERSION
|
622
|
+
metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
|
623
|
+
|
624
|
+
header_params = {
|
625
|
+
"parent" => request.parent
|
626
|
+
}
|
627
|
+
request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
|
628
|
+
metadata[:"x-goog-request-params"] ||= request_params_header
|
629
|
+
|
630
|
+
options.apply_defaults timeout: @config.rpcs.translate_document.timeout,
|
631
|
+
metadata: metadata,
|
632
|
+
retry_policy: @config.rpcs.translate_document.retry_policy
|
633
|
+
|
634
|
+
options.apply_defaults timeout: @config.timeout,
|
635
|
+
metadata: @config.metadata,
|
636
|
+
retry_policy: @config.retry_policy
|
637
|
+
|
638
|
+
@translation_service_stub.call_rpc :translate_document, request, options: options do |response, operation|
|
639
|
+
yield response, operation if block_given?
|
640
|
+
return response
|
641
|
+
end
|
642
|
+
rescue ::GRPC::BadStatus => e
|
643
|
+
raise ::Google::Cloud::Error.from_error(e)
|
644
|
+
end
|
645
|
+
|
528
646
|
##
|
529
647
|
# Translates a large volume of text in asynchronous batch mode.
|
530
648
|
# This function provides real-time output as the inputs are being processed.
|
@@ -575,14 +693,13 @@ module Google
|
|
575
693
|
#
|
576
694
|
# - General (built-in) models:
|
577
695
|
# `projects/{project-number-or-id}/locations/{location-id}/models/general/nmt`,
|
578
|
-
# `projects/{project-number-or-id}/locations/{location-id}/models/general/base`
|
579
696
|
#
|
580
697
|
#
|
581
698
|
# If the map is empty or a specific model is
|
582
699
|
# not requested for a language pair, then default google model (nmt) is used.
|
583
700
|
# @param input_configs [::Array<::Google::Cloud::Translate::V3::InputConfig, ::Hash>]
|
584
701
|
# Required. Input configurations.
|
585
|
-
# The total number of files matched should be <=
|
702
|
+
# The total number of files matched should be <= 100.
|
586
703
|
# The total content size should be <= 100M Unicode codepoints.
|
587
704
|
# The files must use UTF-8 encoding.
|
588
705
|
# @param output_config [::Google::Cloud::Translate::V3::OutputConfig, ::Hash]
|
@@ -600,7 +717,8 @@ module Google
|
|
600
717
|
# characters, underscores and dashes. International characters are allowed.
|
601
718
|
# Label values are optional. Label keys must start with a letter.
|
602
719
|
#
|
603
|
-
# See https://cloud.google.com/translate/docs/labels for more
|
720
|
+
# See https://cloud.google.com/translate/docs/advanced/labels for more
|
721
|
+
# information.
|
604
722
|
#
|
605
723
|
# @yield [response, operation] Access the result along with the RPC operation
|
606
724
|
# @yieldparam response [::Gapic::Operation]
|
@@ -636,7 +754,9 @@ module Google
|
|
636
754
|
options.apply_defaults timeout: @config.rpcs.batch_translate_text.timeout,
|
637
755
|
metadata: metadata,
|
638
756
|
retry_policy: @config.rpcs.batch_translate_text.retry_policy
|
639
|
-
|
757
|
+
|
758
|
+
options.apply_defaults timeout: @config.timeout,
|
759
|
+
metadata: @config.metadata,
|
640
760
|
retry_policy: @config.retry_policy
|
641
761
|
|
642
762
|
@translation_service_stub.call_rpc :batch_translate_text, request, options: options do |response, operation|
|
@@ -648,6 +768,134 @@ module Google
|
|
648
768
|
raise ::Google::Cloud::Error.from_error(e)
|
649
769
|
end
|
650
770
|
|
771
|
+
##
|
772
|
+
# Translates a large volume of document in asynchronous batch mode.
|
773
|
+
# This function provides real-time output as the inputs are being processed.
|
774
|
+
# If caller cancels a request, the partial results (for an input file, it's
|
775
|
+
# all or nothing) may still be available on the specified output location.
|
776
|
+
#
|
777
|
+
# This call returns immediately and you can use
|
778
|
+
# google.longrunning.Operation.name to poll the status of the call.
|
779
|
+
#
|
780
|
+
# @overload batch_translate_document(request, options = nil)
|
781
|
+
# Pass arguments to `batch_translate_document` via a request object, either of type
|
782
|
+
# {::Google::Cloud::Translate::V3::BatchTranslateDocumentRequest} or an equivalent Hash.
|
783
|
+
#
|
784
|
+
# @param request [::Google::Cloud::Translate::V3::BatchTranslateDocumentRequest, ::Hash]
|
785
|
+
# A request object representing the call parameters. Required. To specify no
|
786
|
+
# parameters, or to keep all the default parameter values, pass an empty Hash.
|
787
|
+
# @param options [::Gapic::CallOptions, ::Hash]
|
788
|
+
# Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
|
789
|
+
#
|
790
|
+
# @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)
|
791
|
+
# Pass arguments to `batch_translate_document` via keyword arguments. Note that at
|
792
|
+
# least one keyword argument is required. To specify no parameters, or to keep all
|
793
|
+
# the default parameter values, pass an empty Hash as a request object (see above).
|
794
|
+
#
|
795
|
+
# @param parent [::String]
|
796
|
+
# Required. Location to make a regional call.
|
797
|
+
#
|
798
|
+
# Format: `projects/{project-number-or-id}/locations/{location-id}`.
|
799
|
+
#
|
800
|
+
# The `global` location is not supported for batch translation.
|
801
|
+
#
|
802
|
+
# Only AutoML Translation models or glossaries within the same region (have
|
803
|
+
# the same location-id) can be used, otherwise an INVALID_ARGUMENT (400)
|
804
|
+
# error is returned.
|
805
|
+
# @param source_language_code [::String]
|
806
|
+
# Required. The BCP-47 language code of the input document if known, for
|
807
|
+
# example, "en-US" or "sr-Latn". Supported language codes are listed in
|
808
|
+
# Language Support (https://cloud.google.com/translate/docs/languages).
|
809
|
+
# @param target_language_codes [::Array<::String>]
|
810
|
+
# Required. The BCP-47 language code to use for translation of the input
|
811
|
+
# document. Specify up to 10 language codes here.
|
812
|
+
# @param input_configs [::Array<::Google::Cloud::Translate::V3::BatchDocumentInputConfig, ::Hash>]
|
813
|
+
# Required. Input configurations.
|
814
|
+
# The total number of files matched should be <= 100.
|
815
|
+
# The total content size to translate should be <= 100M Unicode codepoints.
|
816
|
+
# The files must use UTF-8 encoding.
|
817
|
+
# @param output_config [::Google::Cloud::Translate::V3::BatchDocumentOutputConfig, ::Hash]
|
818
|
+
# Required. Output configuration.
|
819
|
+
# If 2 input configs match to the same file (that is, same input path),
|
820
|
+
# we don't generate output for duplicate inputs.
|
821
|
+
# @param models [::Hash{::String => ::String}]
|
822
|
+
# Optional. The models to use for translation. Map's key is target language
|
823
|
+
# code. Map's value is the model name. Value can be a built-in general model,
|
824
|
+
# or an AutoML Translation model.
|
825
|
+
#
|
826
|
+
# The value format depends on model type:
|
827
|
+
#
|
828
|
+
# - AutoML Translation models:
|
829
|
+
# `projects/{project-number-or-id}/locations/{location-id}/models/{model-id}`
|
830
|
+
#
|
831
|
+
# - General (built-in) models:
|
832
|
+
# `projects/{project-number-or-id}/locations/{location-id}/models/general/nmt`,
|
833
|
+
#
|
834
|
+
#
|
835
|
+
# If the map is empty or a specific model is
|
836
|
+
# not requested for a language pair, then default google model (nmt) is used.
|
837
|
+
# @param glossaries [::Hash{::String => ::Google::Cloud::Translate::V3::TranslateTextGlossaryConfig, ::Hash}]
|
838
|
+
# Optional. Glossaries to be applied. It's keyed by target language code.
|
839
|
+
# @param format_conversions [::Hash{::String => ::String}]
|
840
|
+
# Optional. File format conversion map to be applied to all input files.
|
841
|
+
# Map's key is the original mime_type. Map's value is the target mime_type of
|
842
|
+
# translated documents.
|
843
|
+
#
|
844
|
+
# Supported file format conversion includes:
|
845
|
+
# - `application/pdf` to
|
846
|
+
# `application/vnd.openxmlformats-officedocument.wordprocessingml.document`
|
847
|
+
#
|
848
|
+
# If nothing specified, output files will be in the same format as the
|
849
|
+
# original file.
|
850
|
+
#
|
851
|
+
# @yield [response, operation] Access the result along with the RPC operation
|
852
|
+
# @yieldparam response [::Gapic::Operation]
|
853
|
+
# @yieldparam operation [::GRPC::ActiveCall::Operation]
|
854
|
+
#
|
855
|
+
# @return [::Gapic::Operation]
|
856
|
+
#
|
857
|
+
# @raise [::Google::Cloud::Error] if the RPC is aborted.
|
858
|
+
#
|
859
|
+
def batch_translate_document request, options = nil
|
860
|
+
raise ::ArgumentError, "request must be provided" if request.nil?
|
861
|
+
|
862
|
+
request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Translate::V3::BatchTranslateDocumentRequest
|
863
|
+
|
864
|
+
# Converts hash and nil to an options object
|
865
|
+
options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
|
866
|
+
|
867
|
+
# Customize the options with defaults
|
868
|
+
metadata = @config.rpcs.batch_translate_document.metadata.to_h
|
869
|
+
|
870
|
+
# Set x-goog-api-client and x-goog-user-project headers
|
871
|
+
metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
|
872
|
+
lib_name: @config.lib_name, lib_version: @config.lib_version,
|
873
|
+
gapic_version: ::Google::Cloud::Translate::V3::VERSION
|
874
|
+
metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
|
875
|
+
|
876
|
+
header_params = {
|
877
|
+
"parent" => request.parent
|
878
|
+
}
|
879
|
+
request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
|
880
|
+
metadata[:"x-goog-request-params"] ||= request_params_header
|
881
|
+
|
882
|
+
options.apply_defaults timeout: @config.rpcs.batch_translate_document.timeout,
|
883
|
+
metadata: metadata,
|
884
|
+
retry_policy: @config.rpcs.batch_translate_document.retry_policy
|
885
|
+
|
886
|
+
options.apply_defaults timeout: @config.timeout,
|
887
|
+
metadata: @config.metadata,
|
888
|
+
retry_policy: @config.retry_policy
|
889
|
+
|
890
|
+
@translation_service_stub.call_rpc :batch_translate_document, request, options: options do |response, operation|
|
891
|
+
response = ::Gapic::Operation.new response, @operations_client, options: options
|
892
|
+
yield response, operation if block_given?
|
893
|
+
return response
|
894
|
+
end
|
895
|
+
rescue ::GRPC::BadStatus => e
|
896
|
+
raise ::Google::Cloud::Error.from_error(e)
|
897
|
+
end
|
898
|
+
|
651
899
|
##
|
652
900
|
# Creates a glossary and returns the long-running operation. Returns
|
653
901
|
# NOT_FOUND, if the project doesn't exist.
|
@@ -706,7 +954,9 @@ module Google
|
|
706
954
|
options.apply_defaults timeout: @config.rpcs.create_glossary.timeout,
|
707
955
|
metadata: metadata,
|
708
956
|
retry_policy: @config.rpcs.create_glossary.retry_policy
|
709
|
-
|
957
|
+
|
958
|
+
options.apply_defaults timeout: @config.timeout,
|
959
|
+
metadata: @config.metadata,
|
710
960
|
retry_policy: @config.retry_policy
|
711
961
|
|
712
962
|
@translation_service_stub.call_rpc :create_glossary, request, options: options do |response, operation|
|
@@ -749,7 +999,20 @@ module Google
|
|
749
999
|
# The first page is returned if `page_token`is empty or missing.
|
750
1000
|
# @param filter [::String]
|
751
1001
|
# Optional. Filter specifying constraints of a list operation.
|
752
|
-
#
|
1002
|
+
# Specify the constraint by the format of "key=value", where key must be
|
1003
|
+
# "src" or "tgt", and the value must be a valid language code.
|
1004
|
+
# For multiple restrictions, concatenate them by "AND" (uppercase only),
|
1005
|
+
# such as: "src=en-US AND tgt=zh-CN". Notice that the exact match is used
|
1006
|
+
# here, which means using 'en-US' and 'en' can lead to different results,
|
1007
|
+
# which depends on the language code you used when you create the glossary.
|
1008
|
+
# For the unidirectional glossaries, the "src" and "tgt" add restrictions
|
1009
|
+
# on the source and target language code separately.
|
1010
|
+
# For the equivalent term set glossaries, the "src" and/or "tgt" add
|
1011
|
+
# restrictions on the term set.
|
1012
|
+
# For example: "src=en-US AND tgt=zh-CN" will only pick the unidirectional
|
1013
|
+
# glossaries which exactly match the source language code as "en-US" and the
|
1014
|
+
# target language code "zh-CN", but all equivalent term set glossaries which
|
1015
|
+
# contain "en-US" and "zh-CN" in their language set will be picked.
|
753
1016
|
# If missing, no filtering is performed.
|
754
1017
|
#
|
755
1018
|
# @yield [response, operation] Access the result along with the RPC operation
|
@@ -786,7 +1049,9 @@ module Google
|
|
786
1049
|
options.apply_defaults timeout: @config.rpcs.list_glossaries.timeout,
|
787
1050
|
metadata: metadata,
|
788
1051
|
retry_policy: @config.rpcs.list_glossaries.retry_policy
|
789
|
-
|
1052
|
+
|
1053
|
+
options.apply_defaults timeout: @config.timeout,
|
1054
|
+
metadata: @config.metadata,
|
790
1055
|
retry_policy: @config.retry_policy
|
791
1056
|
|
792
1057
|
@translation_service_stub.call_rpc :list_glossaries, request, options: options do |response, operation|
|
@@ -854,7 +1119,9 @@ module Google
|
|
854
1119
|
options.apply_defaults timeout: @config.rpcs.get_glossary.timeout,
|
855
1120
|
metadata: metadata,
|
856
1121
|
retry_policy: @config.rpcs.get_glossary.retry_policy
|
857
|
-
|
1122
|
+
|
1123
|
+
options.apply_defaults timeout: @config.timeout,
|
1124
|
+
metadata: @config.metadata,
|
858
1125
|
retry_policy: @config.retry_policy
|
859
1126
|
|
860
1127
|
@translation_service_stub.call_rpc :get_glossary, request, options: options do |response, operation|
|
@@ -922,7 +1189,9 @@ module Google
|
|
922
1189
|
options.apply_defaults timeout: @config.rpcs.delete_glossary.timeout,
|
923
1190
|
metadata: metadata,
|
924
1191
|
retry_policy: @config.rpcs.delete_glossary.retry_policy
|
925
|
-
|
1192
|
+
|
1193
|
+
options.apply_defaults timeout: @config.timeout,
|
1194
|
+
metadata: @config.metadata,
|
926
1195
|
retry_policy: @config.retry_policy
|
927
1196
|
|
928
1197
|
@translation_service_stub.call_rpc :delete_glossary, request, options: options do |response, operation|
|
@@ -947,22 +1216,21 @@ module Google
|
|
947
1216
|
# Configuration can be applied globally to all clients, or to a single client
|
948
1217
|
# on construction.
|
949
1218
|
#
|
950
|
-
#
|
1219
|
+
# @example
|
951
1220
|
#
|
952
|
-
#
|
953
|
-
# to 20 seconds,
|
1221
|
+
# # Modify the global config, setting the timeout for
|
1222
|
+
# # translate_text to 20 seconds,
|
1223
|
+
# # and all remaining timeouts to 10 seconds.
|
1224
|
+
# ::Google::Cloud::Translate::V3::TranslationService::Client.configure do |config|
|
1225
|
+
# config.timeout = 10.0
|
1226
|
+
# config.rpcs.translate_text.timeout = 20.0
|
1227
|
+
# end
|
954
1228
|
#
|
955
|
-
#
|
956
|
-
#
|
957
|
-
#
|
958
|
-
#
|
959
|
-
#
|
960
|
-
# To apply the above configuration only to a new client:
|
961
|
-
#
|
962
|
-
# client = ::Google::Cloud::Translate::V3::TranslationService::Client.new do |config|
|
963
|
-
# config.timeout = 10.0
|
964
|
-
# config.rpcs.translate_text.timeout = 20.0
|
965
|
-
# end
|
1229
|
+
# # Apply the above configuration only to a new client.
|
1230
|
+
# client = ::Google::Cloud::Translate::V3::TranslationService::Client.new do |config|
|
1231
|
+
# config.timeout = 10.0
|
1232
|
+
# config.rpcs.translate_text.timeout = 20.0
|
1233
|
+
# end
|
966
1234
|
#
|
967
1235
|
# @!attribute [rw] endpoint
|
968
1236
|
# The hostname or hostname:port of the service endpoint.
|
@@ -1086,11 +1354,21 @@ module Google
|
|
1086
1354
|
#
|
1087
1355
|
attr_reader :get_supported_languages
|
1088
1356
|
##
|
1357
|
+
# RPC-specific configuration for `translate_document`
|
1358
|
+
# @return [::Gapic::Config::Method]
|
1359
|
+
#
|
1360
|
+
attr_reader :translate_document
|
1361
|
+
##
|
1089
1362
|
# RPC-specific configuration for `batch_translate_text`
|
1090
1363
|
# @return [::Gapic::Config::Method]
|
1091
1364
|
#
|
1092
1365
|
attr_reader :batch_translate_text
|
1093
1366
|
##
|
1367
|
+
# RPC-specific configuration for `batch_translate_document`
|
1368
|
+
# @return [::Gapic::Config::Method]
|
1369
|
+
#
|
1370
|
+
attr_reader :batch_translate_document
|
1371
|
+
##
|
1094
1372
|
# RPC-specific configuration for `create_glossary`
|
1095
1373
|
# @return [::Gapic::Config::Method]
|
1096
1374
|
#
|
@@ -1119,8 +1397,12 @@ module Google
|
|
1119
1397
|
@detect_language = ::Gapic::Config::Method.new detect_language_config
|
1120
1398
|
get_supported_languages_config = parent_rpcs.get_supported_languages if parent_rpcs.respond_to? :get_supported_languages
|
1121
1399
|
@get_supported_languages = ::Gapic::Config::Method.new get_supported_languages_config
|
1400
|
+
translate_document_config = parent_rpcs.translate_document if parent_rpcs.respond_to? :translate_document
|
1401
|
+
@translate_document = ::Gapic::Config::Method.new translate_document_config
|
1122
1402
|
batch_translate_text_config = parent_rpcs.batch_translate_text if parent_rpcs.respond_to? :batch_translate_text
|
1123
1403
|
@batch_translate_text = ::Gapic::Config::Method.new batch_translate_text_config
|
1404
|
+
batch_translate_document_config = parent_rpcs.batch_translate_document if parent_rpcs.respond_to? :batch_translate_document
|
1405
|
+
@batch_translate_document = ::Gapic::Config::Method.new batch_translate_document_config
|
1124
1406
|
create_glossary_config = parent_rpcs.create_glossary if parent_rpcs.respond_to? :create_glossary
|
1125
1407
|
@create_glossary = ::Gapic::Config::Method.new create_glossary_config
|
1126
1408
|
list_glossaries_config = parent_rpcs.list_glossaries if parent_rpcs.respond_to? :list_glossaries
|