google-cloud-translate 1.2.4 → 3.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +5 -8
- data/AUTHENTICATION.md +78 -106
- data/LICENSE.md +201 -0
- data/MIGRATING.md +302 -0
- data/README.md +139 -0
- data/lib/google/cloud/translate/helpers.rb +107 -0
- data/lib/google/cloud/translate/version.rb +6 -2
- data/lib/google/cloud/translate.rb +79 -146
- data/lib/google-cloud-translate.rb +5 -157
- metadata +50 -77
- data/CHANGELOG.md +0 -76
- data/CODE_OF_CONDUCT.md +0 -40
- data/CONTRIBUTING.md +0 -188
- data/LICENSE +0 -201
- data/OVERVIEW.md +0 -185
- data/TROUBLESHOOTING.md +0 -37
- data/lib/google/cloud/translate/api.rb +0 -274
- data/lib/google/cloud/translate/credentials.rb +0 -57
- data/lib/google/cloud/translate/detection.rb +0 -139
- data/lib/google/cloud/translate/language.rb +0 -70
- data/lib/google/cloud/translate/service.rb +0 -208
- data/lib/google/cloud/translate/translation.rb +0 -125
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.5+.
|
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.5
|
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.
|
@@ -0,0 +1,107 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2020 Google LLC
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
|
18
|
+
module Google
|
19
|
+
module Cloud
|
20
|
+
module Translate
|
21
|
+
##
|
22
|
+
# Creates a new object for connecting to the legacy V2 version of the
|
23
|
+
# Cloud Translation API.
|
24
|
+
#
|
25
|
+
# Like other Cloud Platform services, Google Cloud Translation API supports authentication using a project ID
|
26
|
+
# and OAuth 2.0 credentials. In addition, it supports authentication using a public API access key. (If both the
|
27
|
+
# API key and the project and OAuth 2.0 credentials are provided, the API key will be used.) Instructions and
|
28
|
+
# configuration options are covered in the {file:AUTHENTICATION.md Authentication Guide}.
|
29
|
+
#
|
30
|
+
# @param [String] project_id Project identifier for the Cloud Translation service you are connecting to. If not
|
31
|
+
# present, the default project for the credentials is used.
|
32
|
+
# @param [String, Hash, Google::Auth::Credentials] credentials The path to the keyfile as a String, the contents
|
33
|
+
# of the keyfile as a Hash, or a Google::Auth::Credentials object.
|
34
|
+
# @param [String] key a public API access key (not an OAuth 2.0 token)
|
35
|
+
# @param [String, Array<String>] scope The OAuth 2.0 scopes controlling the set of resources and operations that
|
36
|
+
# the connection can access. See [Using OAuth 2.0 to Access Google
|
37
|
+
# APIs](https://developers.google.com/identity/protocols/OAuth2).
|
38
|
+
#
|
39
|
+
# The default scope is:
|
40
|
+
#
|
41
|
+
# * `https://www.googleapis.com/auth/cloud-platform`
|
42
|
+
# @param [Integer] retries Number of times to retry requests on server error. The default value is `3`.
|
43
|
+
# Optional.
|
44
|
+
# @param [Integer] timeout Default timeout to use in requests. Optional.
|
45
|
+
# @param [String] endpoint Override of the endpoint host name. Optional. If the param is nil, uses the default
|
46
|
+
# endpoint.
|
47
|
+
#
|
48
|
+
# @return [Google::Cloud::Translate::V2::Api]
|
49
|
+
#
|
50
|
+
# @example
|
51
|
+
# require "google/cloud/translate/v2"
|
52
|
+
#
|
53
|
+
# translate = Google::Cloud::Translate::V2.new(
|
54
|
+
# version: :v2,
|
55
|
+
# project_id: "my-todo-project",
|
56
|
+
# credentials: "/path/to/keyfile.json"
|
57
|
+
# )
|
58
|
+
#
|
59
|
+
# translation = translate.translate "Hello world!", to: "la"
|
60
|
+
# translation.text #=> "Salve mundi!"
|
61
|
+
#
|
62
|
+
# @example Using API Key.
|
63
|
+
# require "google/cloud/translate/v2"
|
64
|
+
#
|
65
|
+
# translate = Google::Cloud::Translate::V2.new(
|
66
|
+
# key: "api-key-abc123XYZ789"
|
67
|
+
# )
|
68
|
+
#
|
69
|
+
# translation = translate.translate "Hello world!", to: "la"
|
70
|
+
# translation.text #=> "Salve mundi!"
|
71
|
+
#
|
72
|
+
# @example Using API Key from the environment variable.
|
73
|
+
# require "google/cloud/translate/v2"
|
74
|
+
#
|
75
|
+
# ENV["TRANSLATE_KEY"] = "api-key-abc123XYZ789"
|
76
|
+
#
|
77
|
+
# translate = Google::Cloud::Translate::V2.new
|
78
|
+
#
|
79
|
+
# translation = translate.translate "Hello world!", to: "la"
|
80
|
+
# translation.text #=> "Salve mundi!"
|
81
|
+
#
|
82
|
+
def self.translation_v2_service project_id: nil,
|
83
|
+
credentials: nil,
|
84
|
+
key: nil,
|
85
|
+
scope: nil,
|
86
|
+
retries: nil,
|
87
|
+
timeout: nil,
|
88
|
+
endpoint: nil
|
89
|
+
require "google/cloud/translate/v2"
|
90
|
+
Google::Cloud::Translate::V2.new project_id: project_id,
|
91
|
+
credentials: credentials,
|
92
|
+
key: key,
|
93
|
+
scope: scope,
|
94
|
+
retries: retries,
|
95
|
+
timeout: timeout,
|
96
|
+
endpoint: endpoint
|
97
|
+
end
|
98
|
+
|
99
|
+
# Additional config keys used by V2
|
100
|
+
configure do |config|
|
101
|
+
config.add_field! :project_id, nil, match: ::String
|
102
|
+
config.add_field! :key, nil, match: ::String
|
103
|
+
config.add_field! :retries, nil, match: ::Integer
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -1,4 +1,6 @@
|
|
1
|
-
#
|
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,11 +14,13 @@
|
|
12
14
|
# See the License for the specific language governing permissions and
|
13
15
|
# limitations under the License.
|
14
16
|
|
17
|
+
# Auto-generated by gapic-generator-ruby. DO NOT EDIT!
|
18
|
+
|
15
19
|
|
16
20
|
module Google
|
17
21
|
module Cloud
|
18
22
|
module Translate
|
19
|
-
VERSION = "
|
23
|
+
VERSION = "3.2.3"
|
20
24
|
end
|
21
25
|
end
|
22
26
|
end
|