google-cloud-translate 2.2.0 → 3.0.3

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.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +5 -8
  3. data/AUTHENTICATION.md +67 -81
  4. data/LICENSE.md +203 -0
  5. data/MIGRATING.md +302 -0
  6. data/README.md +139 -0
  7. data/lib/google-cloud-translate.rb +5 -146
  8. data/lib/google/cloud/translate.rb +79 -178
  9. data/lib/google/cloud/translate/helpers.rb +107 -0
  10. data/lib/google/cloud/translate/version.rb +6 -2
  11. metadata +35 -135
  12. data/CHANGELOG.md +0 -158
  13. data/CODE_OF_CONDUCT.md +0 -40
  14. data/CONTRIBUTING.md +0 -188
  15. data/LICENSE +0 -201
  16. data/OVERVIEW.md +0 -390
  17. data/TROUBLESHOOTING.md +0 -37
  18. data/lib/google/cloud/translate/v2.rb +0 -169
  19. data/lib/google/cloud/translate/v2/api.rb +0 -255
  20. data/lib/google/cloud/translate/v2/credentials.rb +0 -58
  21. data/lib/google/cloud/translate/v2/detection.rb +0 -132
  22. data/lib/google/cloud/translate/v2/language.rb +0 -68
  23. data/lib/google/cloud/translate/v2/service.rb +0 -205
  24. data/lib/google/cloud/translate/v2/translation.rb +0 -120
  25. data/lib/google/cloud/translate/v3.rb +0 -144
  26. data/lib/google/cloud/translate/v3/credentials.rb +0 -42
  27. data/lib/google/cloud/translate/v3/doc/google/cloud/translate/v3/translation_service.rb +0 -663
  28. data/lib/google/cloud/translate/v3/doc/google/longrunning/operations.rb +0 -51
  29. data/lib/google/cloud/translate/v3/doc/google/protobuf/any.rb +0 -131
  30. data/lib/google/cloud/translate/v3/doc/google/protobuf/timestamp.rb +0 -113
  31. data/lib/google/cloud/translate/v3/doc/google/rpc/status.rb +0 -39
  32. data/lib/google/cloud/translate/v3/translation_service_client.rb +0 -930
  33. data/lib/google/cloud/translate/v3/translation_service_client_config.json +0 -66
  34. data/lib/google/cloud/translate/v3/translation_service_pb.rb +0 -226
  35. data/lib/google/cloud/translate/v3/translation_service_services_pb.rb +0 -68
data/MIGRATING.md ADDED
@@ -0,0 +1,302 @@
1
+ ## Migrating to google-cloud-translate 3.0
2
+
3
+ The 3.0 release of the google-cloud-translate client is a significant upgrade
4
+ based on a [next-gen code generator](https://github.com/googleapis/gapic-generator-ruby),
5
+ and includes substantial interface changes. Existing code written for earlier
6
+ versions of this library will likely require updates to use this version.
7
+ This document describes the changes that have been made, and what you need to
8
+ do to update your usage.
9
+
10
+ To summarize:
11
+
12
+ * The library has been broken out into three libraries. The new gems
13
+ `google-cloud-translate-v2` and `google-cloud-translate-v3` contain the
14
+ actual client classes for versions V2 and V3 of the Translation
15
+ service, and the gem `google-cloud-translate` now simply provides a
16
+ convenience wrapper. See [Library Structure](#library-structure) for more
17
+ info.
18
+ * When creating V3 client objects, you customize the configuration in a block
19
+ instead of passing arguments to the constructor. See
20
+ [Creating Clients](#creating-clients) for more info. When creating V2
21
+ clients, however, pass settings arguments as before.
22
+ * Previously, positional arguments were used to indicate required arguments.
23
+ Now, in the V3 client, all method arguments are keyword arguments, with
24
+ documentation that specifies whether they are required or optional.
25
+ Additionally, you can pass a proto request object instead of separate
26
+ arguments. See [Passing Arguments](#passing-arguments) for more info. V2
27
+ client methods, however, remain unchanged.
28
+ * Previously, some V3 client classes included class methods for constructing
29
+ resource paths. These paths are now instance methods on the client objects,
30
+ and are also available in a separate paths module. See
31
+ [Resource Path Helpers](#resource-path-helpers) for more info.
32
+ * Previously, clients reported RPC errors by raising instances of
33
+ `Google::Gax::GaxError` and its subclasses. Now, RPC exceptions are of type
34
+ `Google::Cloud::Error` and its subclasses. See
35
+ [Handling Errors](#handling-errors) for more info.
36
+ * Some classes have moved into different namespaces. See
37
+ [Class Namespaces](#class-namespaces) for more info.
38
+
39
+ ### Library Structure
40
+
41
+ Older releases of the `google-cloud-translate` gem were all-in-one gems that
42
+ included potentially multiple clients for multiple versions of the Translation
43
+ service. The `Google::Cloud::Translate.new` factory method would
44
+ return you an instance of a `Google::Cloud::Translate::V2::Api`
45
+ object for the V2 version of the service, or a
46
+ `Google::Cloud::Translate::V3::TranslationServiceClient` object for the
47
+ V3 version of the service. All these classes were defined in the same gem.
48
+
49
+ With the 3.0 release, the `google-cloud-translate` gem still provides factory
50
+ methods for obtaining clients. (The method signatures will have changed. See
51
+ [Creating Clients](#creating-clients) for details.) However, the actual client
52
+ classes have been moved into separate gems, one per service version. The
53
+ `Google::Cloud::Translate::V2::Api` class, along with its
54
+ helpers and data types, is now part of the `google-cloud-translate-v2` gem.
55
+ Similarly, the `Google::Cloud::Translate::V3::TranslationService::Client`
56
+ class is part of the `google-cloud-translate-v3` gem.
57
+
58
+ For normal usage, you can continue to install the `google-cloud-translate` gem
59
+ (which will bring in the versioned client gems as dependencies) and continue to
60
+ use factory methods to create clients. However, you may alternatively choose to
61
+ install only one of the versioned gems. For example, if you know you will use only
62
+ `V2` of the service, you can install `google-cloud-translate-v2` by itself, and
63
+ call `Google::Cloud::Translate::V2.new` to create V2 clients directly.
64
+
65
+ ### Creating Clients
66
+
67
+ In older releases, to create a client object, you would use the
68
+ `Google::Cloud::Translate.new` class method. Keyword arguments were available to
69
+ select a service version and to configure parameters such as credentials and
70
+ timeouts. Furthermore, you could configure default parameters using the
71
+ `Google::Cloud::Translate.configure` method.
72
+
73
+ In the 3.0 release, there are separate class methods for creating clients of the
74
+ modern (V3) and legacy (V2) Translation services. To create a V2 client, use the
75
+ `translation_v2_service` class method, which takes the same keyword arguments
76
+ you would have used previously. To create a V3 (or later) client, use the
77
+ `translation_service` class method and set options in a configuration block.
78
+
79
+ Old (V3):
80
+ ```
81
+ client = Google::Cloud::Translate.new credentials: "/path/to/credentials.json"
82
+ ```
83
+
84
+ Old (V2):
85
+ ```
86
+ client = Google::Cloud::Translate.new version: :v2,
87
+ credentials: "/path/to/credentials.json"
88
+ ```
89
+
90
+ New (V3):
91
+ ```
92
+ # Call the translation_service method to create a V3 client,
93
+ # and pass a block to configure the client.
94
+ client = Google::Cloud::Translate.translation_service do |config|
95
+ config.credentials = "/path/to/credentials.json"
96
+ end
97
+
98
+ # You can omit the block if you're keeping the default configuration
99
+ default_client = Google::Cloud::Translate.translation_service
100
+ ```
101
+
102
+ New (V2):
103
+ ```
104
+ # Call the separate translation_v2_service method to create a legacy V2 client,
105
+ # and pass configuration as keyword arguments.
106
+ client = Google::Cloud::Translate.translation_v2_service(
107
+ credentials: "/path/to/credentials.json")
108
+ ```
109
+
110
+ ### Passing Arguments
111
+
112
+ In older releases, required arguments would be passed as positional method
113
+ arguments, while most optional arguments would be passed as keyword arguments.
114
+
115
+ With the 3.0 release, the V2 client interface remains the same, but in the V3
116
+ client interface, all RPC arguments are passed as keyword arguments, regardless
117
+ of whether they are required or optional. For example:
118
+
119
+ Old (V3):
120
+ ```
121
+ client = Google::Cloud::Translate.new
122
+
123
+ # Contents, target language, and project are positional arguments, but
124
+ # mime type is a keyword argument
125
+ response = client.translate_text ["Hello, world!"], "es", "my-project",
126
+ mime_type: "text/plain"
127
+ ```
128
+
129
+ New (V3):
130
+ ```
131
+ client = Google::Cloud::Translate.translation_service
132
+
133
+ # All arguments are keyword arguments
134
+ response = client.translate_text content: ["Hello, world!"],
135
+ target_language_code: "es",
136
+ parent: "my-project",
137
+ mime_type: "text/plain"
138
+ ```
139
+
140
+ In the 3.0 release, it is also possible to pass a request object, either
141
+ as a hash or as a protocol buffer.
142
+
143
+ New (V3):
144
+ ```
145
+ client = Google::Cloud::Translate.translation_service
146
+
147
+ request = Google::Cloud::Translate::V3::TranslateTextRequest.new(
148
+ content: ["Hello, world!"],
149
+ target_language_code: "es",
150
+ parent: "my-project",
151
+ mime_type: "text/plain"
152
+ )
153
+
154
+ # Pass a request object as a positional argument:
155
+ response = client.translate_text request
156
+ ```
157
+
158
+ Finally, in older releases, to provide call options, you would pass a
159
+ `Google::Gax::CallOptions` object with the `:options` keyword argument. In the
160
+ 3.0 release, pass call options using a _second set_ of keyword arguments.
161
+
162
+ Old (V3):
163
+ ```
164
+ client = Google::Cloud::Translate.new
165
+
166
+ options = Google::Gax::CallOptions.new timeout: 10.0
167
+
168
+ response = client.translate_text ["Hello, world!"], "es", "my-project",
169
+ mime_type: "text/plain",
170
+ options: options
171
+ ```
172
+
173
+ New (V3):
174
+ ```
175
+ client = Google::Cloud::Translate.translation_service
176
+
177
+ # Use a hash to wrap the normal call arguments (or pass a request object), and
178
+ # then add further keyword arguments for the call options.
179
+ response = client.translate_text(
180
+ { content: ["Hello, world!"], target_language_code: "es",
181
+ parent: "my-project", mime_type: "text/plain" },
182
+ timeout: 10.0
183
+ )
184
+ ```
185
+
186
+ ### Resource Path Helpers
187
+
188
+ The client library for the V3 service includes helper methods for generating
189
+ the resource path strings passed to many calls. These helpers have changed in
190
+ two ways:
191
+
192
+ * In older releases, they are _class_ methods on the client class. In the 1.0
193
+ release, they are _instance_ methods on the client. They are also available
194
+ on a separate paths module that you can include elsewhere for convenience.
195
+ * In older releases, arguments to a resource path helper are passed as
196
+ _positional_ arguments. In the 3.0 release, they are passed as named _keyword_
197
+ arguments.
198
+
199
+ Following is an example involving using a resource path helper.
200
+
201
+ Old (V3):
202
+ ```
203
+ client = Google::Cloud::Translate.new
204
+
205
+ # Call the helper on the client class
206
+ name = Google::Cloud::Translate::V3::TranslationServiceClient.glossary_path(
207
+ "my-project", "my-location", "my-glossary"
208
+ )
209
+
210
+ response = client.get_glossary name
211
+ ```
212
+
213
+ New (V3):
214
+ ```
215
+ client = Google::Cloud::Translate.translation_service
216
+
217
+ # Call the helper on the client instance, and use keyword arguments
218
+ name = client.glossary_path project: "my-project", location: "my-location",
219
+ glossary: "my-glossary"
220
+
221
+ response = client.get_glossary name: name
222
+ ```
223
+
224
+ In the 3.0 client, you can also use the paths module as a convenience module.
225
+
226
+ New (V3):
227
+ ```
228
+ # Bring the path methods into the current class
229
+ include Google::Cloud::Translate::V3::TranslationService::Paths
230
+
231
+ def foo
232
+ client = Google::Cloud::Translate.translation_service
233
+
234
+ # Call the included helper method
235
+ name = glossary_path project: "my-project", location: "my-location",
236
+ glossary: "my-glossary"
237
+
238
+ response = client.get_glossary name: name
239
+
240
+ # Do something with response...
241
+ end
242
+ ```
243
+
244
+ ### Handling Errors
245
+
246
+ The client reports standard
247
+ [gRPC error codes](https://github.com/grpc/grpc/blob/master/doc/statuscodes.md)
248
+ by raising exceptions. In older releases, these exceptions were located in the
249
+ `Google::Gax` namespace and were subclasses of the `Google::Gax::GaxError` base
250
+ exception class, defined in the `google-gax` gem. However, these classes were
251
+ different from the standard exceptions (subclasses of `Google::Cloud::Error`)
252
+ thrown by other client libraries such as `google-cloud-storage`.
253
+
254
+ The 3.0 client library now uses the `Google::Cloud::Error` exception hierarchy,
255
+ for consistency across all the Google Cloud client libraries. In general, these
256
+ exceptions have the same name as their counterparts from older releases, but
257
+ are located in the `Google::Cloud` namespace rather than the `Google::Gax`
258
+ namespace.
259
+
260
+ Old (V3):
261
+ ```
262
+ client = Google::Cloud::Translate.new
263
+
264
+ begin
265
+ response = client.translate_text ["Hello, world!"], "es", "my-project",
266
+ mime_type: "text/plain"
267
+ rescue Google::Gax::Error => e
268
+ # Handle exceptions that subclass Google::Gax::Error
269
+ end
270
+ ```
271
+
272
+ New (V3):
273
+ ```
274
+ client = Google::Cloud::Translate.translation_service
275
+
276
+ begin
277
+ response = client.translate_text content: ["Hello, world!"],
278
+ target_language_code: "es",
279
+ parent: "my-project",
280
+ mime_type: "text/plain"
281
+ rescue Google::Cloud::Error => e
282
+ # Handle exceptions that subclass Google::Cloud::Error
283
+ end
284
+ ```
285
+
286
+ ### Class Namespaces
287
+
288
+ In older releases, the client object for V3 was of class
289
+ `Google::Cloud::Translate::V3::TranslationServiceClient`.
290
+ In the 3.0 release, the client object is of class
291
+ `Google::Cloud::Translate::V3::TranslationService::Client`.
292
+ Note that most users will use the `Google::Cloud::Translate.translation_service`
293
+ factory method to create instances of the client object, so you may not need to
294
+ reference the actual class directly. See [Creating Clients](#creating-clients).
295
+
296
+ In older releases, the V3 credentials object was of class
297
+ `Google::Cloud::Translate::V3::Credentials`.
298
+ In the 3.0 release, the credentials object is of class
299
+ `Google::Cloud::Translate::V3::TranslationService::Credentials`.
300
+ Again, most users will not need to reference this class directly.
301
+
302
+ The V2 classes have not been renamed.
data/README.md ADDED
@@ -0,0 +1,139 @@
1
+ # Ruby Client for the Cloud Translation API
2
+
3
+ API Client library for the Cloud Translation API
4
+
5
+ Cloud Translation can dynamically translate text between thousands of language pairs. Translation lets websites and programs programmatically integrate with the translation service.
6
+
7
+ Actual client classes for the various versions of this API are defined in
8
+ _versioned_ client gems, with names of the form `google-cloud-translate-v*`.
9
+ The gem `google-cloud-translate` is the main client library that brings the
10
+ verisoned gems in as dependencies, and provides high-level methods for
11
+ constructing clients. More information on versioned clients can be found below
12
+ in the section titled *Which client should I use?*.
13
+
14
+ View the [Client Library Documentation](https://googleapis.dev/ruby/google-cloud-translate/latest)
15
+ for this library, google-cloud-translate, to see the convenience methods for
16
+ constructing client objects. Reference documentation for the client objects
17
+ themselves can be found in the client library documentation for the versioned
18
+ client gems:
19
+ [google-cloud-translate-v2](https://googleapis.dev/ruby/google-cloud-translate-v2/latest),
20
+ [google-cloud-translate-v3](https://googleapis.dev/ruby/google-cloud-translate-v3/latest).
21
+
22
+ See also the [Product Documentation](https://cloud.google.com/translate)
23
+ for more usage information.
24
+
25
+ ## Quick Start
26
+
27
+ ```
28
+ $ gem install google-cloud-translate
29
+ ```
30
+
31
+ In order to use this library, you first need to go through the following steps:
32
+
33
+ 1. [Select or create a Cloud Platform project.](https://console.cloud.google.com/project)
34
+ 1. [Enable billing for your project.](https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project)
35
+ 1. [Enable the API.](https://console.cloud.google.com/apis/library/translate.googleapis.com)
36
+ 1. {file:AUTHENTICATION.md Set up authentication.}
37
+
38
+ ## Migrating from 2.x versions
39
+
40
+ The 3.0 release of the google-cloud-translate client is a significant upgrade
41
+ based on a [next-gen code generator](https://github.com/googleapis/gapic-generator-ruby),
42
+ and includes substantial interface changes. Existing code written for earlier
43
+ versions of this library will likely require updates to use this version.
44
+ See the {file:MIGRATING.md MIGRATING.md} document for more information.
45
+
46
+ ## Enabling Logging
47
+
48
+ To enable logging for this library, set the logger for the underlying [gRPC](https://github.com/grpc/grpc/tree/master/src/ruby) library.
49
+ The logger that you set may be a Ruby stdlib [`Logger`](https://ruby-doc.org/stdlib/libdoc/logger/rdoc/Logger.html) as shown below,
50
+ or a [`Google::Cloud::Logging::Logger`](https://googleapis.dev/ruby/google-cloud-logging/latest)
51
+ that will write logs to [Cloud Logging](https://cloud.google.com/logging/). See [grpc/logconfig.rb](https://github.com/grpc/grpc/blob/master/src/ruby/lib/grpc/logconfig.rb)
52
+ and the gRPC [spec_helper.rb](https://github.com/grpc/grpc/blob/master/src/ruby/spec/spec_helper.rb) for additional information.
53
+
54
+ Configuring a Ruby stdlib logger:
55
+
56
+ ```ruby
57
+ require "logger"
58
+
59
+ module MyLogger
60
+ LOGGER = Logger.new $stderr, level: Logger::WARN
61
+ def logger
62
+ LOGGER
63
+ end
64
+ end
65
+
66
+ # Define a gRPC module-level logger method before grpc/logconfig.rb loads.
67
+ module GRPC
68
+ extend MyLogger
69
+ end
70
+ ```
71
+
72
+ ## Supported Ruby Versions
73
+
74
+ This library is supported on Ruby 2.4+.
75
+
76
+ Google provides official support for Ruby versions that are actively supported
77
+ by Ruby Core—that is, Ruby versions that are either in normal maintenance or
78
+ in security maintenance, and not end of life. Currently, this means Ruby 2.4
79
+ and later. Older versions of Ruby _may_ still work, but are unsupported and not
80
+ recommended. See https://www.ruby-lang.org/en/downloads/branches/ for details
81
+ about the Ruby support schedule.
82
+
83
+ ## Which client should I use?
84
+
85
+ Most modern Ruby client libraries for Google APIs come in two flavors: the main
86
+ client library with a name such as `google-cloud-translate`,
87
+ and lower-level _versioned_ client libraries with names such as
88
+ `google-cloud-translate-v2`.
89
+ _In most cases, you should install the main client._
90
+
91
+ ### What's the difference between the main client and a versioned client?
92
+
93
+ A _versioned client_ provides a basic set of data types and client classes for
94
+ a _single version_ of a specific service. (That is, for a service with multiple
95
+ versions, there might be a separate versioned client for each service version.)
96
+ Most versioned clients are written and maintained by a code generator.
97
+
98
+ The _main client_ is designed to provide you with the _recommended_ client
99
+ interfaces for the service. There will be only one main client for any given
100
+ service, even a service with multiple versions. The main client includes
101
+ factory methods for constructing the client objects we recommend for most
102
+ users. In some cases, those will be classes provided by an underlying versioned
103
+ client; in other cases, they will be handwritten higher-level client objects
104
+ with additional capabilities, convenience methods, or best practices built in.
105
+ Generally, the main client will default to a recommended service version,
106
+ although in some cases you can override this if you need to talk to a specific
107
+ service version.
108
+
109
+ ### Why would I want to use the main client?
110
+
111
+ We recommend that most users install the main client gem for a service. You can
112
+ identify this gem as the one _without_ a version in its name, e.g.
113
+ `google-cloud-translate`.
114
+ The main client is recommended because it will embody the best practices for
115
+ accessing the service, and may also provide more convenient interfaces or
116
+ tighter integration into frameworks and third-party libraries. In addition, the
117
+ documentation and samples published by Google will generally demonstrate use of
118
+ the main client.
119
+
120
+ ### Why would I want to use a versioned client?
121
+
122
+ You can use a versioned client if you are content with a possibly lower-level
123
+ class interface, you explicitly want to avoid features provided by the main
124
+ client, or you want to access a specific service version not be covered by the
125
+ main client. You can identify versioned client gems because the service version
126
+ is part of the name, e.g. `google-cloud-translate-v2`.
127
+
128
+ ### What about the google-apis-<name> clients?
129
+
130
+ Client library gems with names that begin with `google-apis-` are based on an
131
+ older code generation technology. They talk to a REST/JSON backend (whereas
132
+ most modern clients talk to a [gRPC](https://grpc.io/) backend) and they may
133
+ not offer the same performance, features, and ease of use provided by more
134
+ modern clients.
135
+
136
+ The `google-apis-` clients have wide coverage across Google services, so you
137
+ might need to use one if there is no modern client available for the service.
138
+ However, if a modern client is available, we generally recommend it over the
139
+ older `google-apis-` clients.
@@ -1,4 +1,6 @@
1
- # Copyright 2016 Google LLC
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2020 Google LLC
2
4
  #
3
5
  # Licensed under the Apache License, Version 2.0 (the "License");
4
6
  # you may not use this file except in compliance with the License.
@@ -12,149 +14,6 @@
12
14
  # See the License for the specific language governing permissions and
13
15
  # limitations under the License.
14
16
 
15
- ##
16
- # This file is here to be autorequired by bundler, so that the
17
- # Google::Cloud.translate and Google::Cloud#translate methods can be available,
18
- # but the library and all dependencies won't be loaded until required and used.
19
-
20
-
21
- gem "google-cloud-core"
22
- require "google/cloud" unless defined? Google::Cloud.new
23
- require "google/cloud/config"
24
- require "googleauth"
25
-
26
- module Google
27
- module Cloud
28
- ##
29
- # Creates a new object for connecting to the Cloud Translation API. Each call creates a new connection.
30
- #
31
- # For more information on connecting to Google Cloud see the {file:AUTHENTICATION.md Authentication Guide}.
32
- #
33
- # To use the legacy v2 client, call {Google::Cloud::Translate.new} and specify `version: :v2`.
34
- #
35
- # @param [String] key a public API access key (not an OAuth 2.0 token)
36
- # @param [String, Array<String>] scopes The OAuth 2.0 scopes controlling the set of resources and operations that
37
- # the connection can access. See [Using OAuth 2.0 to Access Google
38
- # APIs](https://developers.google.com/identity/protocols/OAuth2).
39
- #
40
- # The default scopes are:
41
- #
42
- # * `https://www.googleapis.com/auth/cloud-platform`
43
- # * `https://www.googleapis.com/auth/cloud-translation`
44
- # @param [Integer] timeout Default timeout to use in requests. Optional.
45
- #
46
- # @return [Google::Cloud::Translate::V3::TranslationServiceClient]
47
- #
48
- # @example
49
- # require "google/cloud"
50
- #
51
- # gcloud = Google::Cloud.new
52
- # client = gcloud.translate
53
- #
54
- # project_id = "my-project-id"
55
- # location_id = "us-central1"
56
- # model_id = "my-automl-model-id"
57
- #
58
- # # The `model` type requested for this translation.
59
- # model = "projects/#{project_id}/locations/#{location_id}/models/#{model_id}"
60
- # # The content to translate in string format
61
- # contents = ["Hello, world!"]
62
- # # Required. The BCP-47 language code to use for translation.
63
- # target_language = "fr"
64
- # # Optional. The BCP-47 language code of the input text.
65
- # source_language = "en"
66
- # # Optional. Can be "text/plain" or "text/html".
67
- # mime_type = "text/plain"
68
- # parent = client.class.location_path project_id, location_id
69
- #
70
- # response = client.translate_text contents, target_language, parent,
71
- # source_language_code: source_language, model: model, mime_type: mime_type
72
- #
73
- # # Display the translation for each input text provided
74
- # response.translations.each do |translation|
75
- # puts "Translated text: #{translation.translated_text}"
76
- # end
77
- #
78
- def translate scopes: nil, timeout: nil
79
- Google::Cloud.translate credentials: @keyfile, scopes: scopes, timeout: (timeout || @timeout)
80
- end
81
-
82
- ##
83
- # Creates a new object for connecting to the Cloud Translation API. Each call creates a new connection.
84
- #
85
- # For more information on connecting to Google Cloud see the {file:AUTHENTICATION.md Authentication Guide}.
86
- #
87
- # To use the legacy v2 client, call {Google::Cloud::Translate.new} and specify `version: :v2`.
88
- #
89
- # @param [String, Hash, Google::Auth::Credentials] credentials The path to the keyfile as a String, the contents of
90
- # the keyfile as a Hash, or a Google::Auth::Credentials object. (See {Google::Cloud::Translate::V3::Credentials})
91
- # @param [String, Array<String>] scopes The OAuth 2.0 scopes controlling the set of resources and operations that
92
- # the connection can access. See [Using OAuth 2.0 to Access Google
93
- # APIs](https://developers.google.com/identity/protocols/OAuth2).
94
- #
95
- # The default scopes are:
96
- #
97
- # * `https://www.googleapis.com/auth/cloud-platform`
98
- # * `https://www.googleapis.com/auth/cloud-translation`
99
- # @param [Integer] timeout Default timeout to use in requests. Optional.
100
- #
101
- # @return [Google::Cloud::Translate::V3::TranslationServiceClient]
102
- #
103
- # @example
104
- # require "google/cloud"
105
- #
106
- # client = Google::Cloud.translate
107
- #
108
- # project_id = "my-project-id"
109
- # location_id = "us-central1"
110
- # model_id = "my-automl-model-id"
111
- #
112
- # # The `model` type requested for this translation.
113
- # model = "projects/#{project_id}/locations/#{location_id}/models/#{model_id}"
114
- # # The content to translate in string format
115
- # contents = ["Hello, world!"]
116
- # # Required. The BCP-47 language code to use for translation.
117
- # target_language = "fr"
118
- # # Optional. The BCP-47 language code of the input text.
119
- # source_language = "en"
120
- # # Optional. Can be "text/plain" or "text/html".
121
- # mime_type = "text/plain"
122
- # parent = client.class.location_path project_id, location_id
123
- #
124
- # response = client.translate_text contents, target_language, parent,
125
- # source_language_code: source_language, model: model, mime_type: mime_type
126
- #
127
- # # Display the translation for each input text provided
128
- # response.translations.each do |translation|
129
- # puts "Translated text: #{translation.translated_text}"
130
- # end
131
- #
132
- def self.translate credentials: nil, scopes: nil, timeout: nil
133
- require "google/cloud/translate/v3"
134
- Google::Cloud::Translate::V3.new credentials: credentials, scopes: scopes, timeout: timeout
135
- end
136
- end
137
- end
138
-
139
- # Set the default translate configuration
140
- Google::Cloud.configure.add_config! :translate do |config|
141
- default_project = Google::Cloud::Config.deferred do
142
- ENV["TRANSLATE_PROJECT"]
143
- end
144
- default_creds = Google::Cloud::Config.deferred do
145
- Google::Cloud::Config.credentials_from_env(
146
- "TRANSLATE_CREDENTIALS", "TRANSLATE_CREDENTIALS_JSON", "TRANSLATE_KEYFILE", "TRANSLATE_KEYFILE_JSON"
147
- )
148
- end
149
- default_key = Google::Cloud::Config.deferred do
150
- ENV["TRANSLATE_KEY"] || ENV["GOOGLE_CLOUD_KEY"]
151
- end
17
+ # Auto-generated by gapic-generator-ruby. DO NOT EDIT!
152
18
 
153
- config.add_field! :project_id, default_project, match: String, allow_nil: true
154
- config.add_field! :credentials, default_creds, match: [String, Hash, Google::Auth::Credentials], allow_nil: true
155
- config.add_field! :key, default_key, match: String, allow_nil: true
156
- config.add_field! :scope, nil, match: [String, Array]
157
- config.add_field! :retries, nil, match: Integer
158
- config.add_field! :timeout, nil, match: Integer
159
- config.add_field! :endpoint, nil, match: String
160
- end
19
+ require "google/cloud/translate" unless defined? Google::Cloud::Translate::VERSION