google-cloud-translate 2.3.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
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 +80 -0
  7. data/lib/google-cloud-translate.rb +5 -146
  8. data/lib/google/cloud/translate.rb +81 -178
  9. data/lib/google/cloud/translate/helpers.rb +100 -0
  10. data/lib/google/cloud/translate/version.rb +6 -2
  11. metadata +35 -135
  12. data/CHANGELOG.md +0 -164
  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 -209
  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
@@ -1,51 +0,0 @@
1
- # Copyright 2020 Google LLC
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # https://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
-
16
- module Google
17
- module Longrunning
18
- # This resource represents a long-running operation that is the result of a
19
- # network API call.
20
- # @!attribute [rw] name
21
- # @return [String]
22
- # The server-assigned name, which is only unique within the same service that
23
- # originally returns it. If you use the default HTTP mapping, the
24
- # `name` should be a resource name ending with `operations/{unique_id}`.
25
- # @!attribute [rw] metadata
26
- # @return [Google::Protobuf::Any]
27
- # Service-specific metadata associated with the operation. It typically
28
- # contains progress information and common metadata such as create time.
29
- # Some services might not provide such metadata. Any method that returns a
30
- # long-running operation should document the metadata type, if any.
31
- # @!attribute [rw] done
32
- # @return [true, false]
33
- # If the value is `false`, it means the operation is still in progress.
34
- # If `true`, the operation is completed, and either `error` or `response` is
35
- # available.
36
- # @!attribute [rw] error
37
- # @return [Google::Rpc::Status]
38
- # The error result of the operation in case of failure or cancellation.
39
- # @!attribute [rw] response
40
- # @return [Google::Protobuf::Any]
41
- # The normal response of the operation in case of success. If the original
42
- # method returns no data on success, such as `Delete`, the response is
43
- # `google.protobuf.Empty`. If the original method is standard
44
- # `Get`/`Create`/`Update`, the response should be the resource. For other
45
- # methods, the response should have the type `XxxResponse`, where `Xxx`
46
- # is the original method name. For example, if the original method name
47
- # is `TakeSnapshot()`, the inferred response type is
48
- # `TakeSnapshotResponse`.
49
- class Operation; end
50
- end
51
- end
@@ -1,131 +0,0 @@
1
- # Copyright 2020 Google LLC
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # https://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
-
16
- module Google
17
- module Protobuf
18
- # `Any` contains an arbitrary serialized protocol buffer message along with a
19
- # URL that describes the type of the serialized message.
20
- #
21
- # Protobuf library provides support to pack/unpack Any values in the form
22
- # of utility functions or additional generated methods of the Any type.
23
- #
24
- # Example 1: Pack and unpack a message in C++.
25
- #
26
- # Foo foo = ...;
27
- # Any any;
28
- # any.PackFrom(foo);
29
- # ...
30
- # if (any.UnpackTo(&foo)) {
31
- # ...
32
- # }
33
- #
34
- # Example 2: Pack and unpack a message in Java.
35
- #
36
- # Foo foo = ...;
37
- # Any any = Any.pack(foo);
38
- # ...
39
- # if (any.is(Foo.class)) {
40
- # foo = any.unpack(Foo.class);
41
- # }
42
- #
43
- # Example 3: Pack and unpack a message in Python.
44
- #
45
- # foo = Foo(...)
46
- # any = Any()
47
- # any.Pack(foo)
48
- # ...
49
- # if any.Is(Foo.DESCRIPTOR):
50
- # any.Unpack(foo)
51
- # ...
52
- #
53
- # Example 4: Pack and unpack a message in Go
54
- #
55
- # foo := &pb.Foo{...}
56
- # any, err := ptypes.MarshalAny(foo)
57
- # ...
58
- # foo := &pb.Foo{}
59
- # if err := ptypes.UnmarshalAny(any, foo); err != nil {
60
- # ...
61
- # }
62
- #
63
- # The pack methods provided by protobuf library will by default use
64
- # 'type.googleapis.com/full.type.name' as the type URL and the unpack
65
- # methods only use the fully qualified type name after the last '/'
66
- # in the type URL, for example "foo.bar.com/x/y.z" will yield type
67
- # name "y.z".
68
- #
69
- #
70
- # = JSON
71
- #
72
- # The JSON representation of an `Any` value uses the regular
73
- # representation of the deserialized, embedded message, with an
74
- # additional field `@type` which contains the type URL. Example:
75
- #
76
- # package google.profile;
77
- # message Person {
78
- # string first_name = 1;
79
- # string last_name = 2;
80
- # }
81
- #
82
- # {
83
- # "@type": "type.googleapis.com/google.profile.Person",
84
- # "firstName": <string>,
85
- # "lastName": <string>
86
- # }
87
- #
88
- # If the embedded message type is well-known and has a custom JSON
89
- # representation, that representation will be embedded adding a field
90
- # `value` which holds the custom JSON in addition to the `@type`
91
- # field. Example (for message {Google::Protobuf::Duration}):
92
- #
93
- # {
94
- # "@type": "type.googleapis.com/google.protobuf.Duration",
95
- # "value": "1.212s"
96
- # }
97
- # @!attribute [rw] type_url
98
- # @return [String]
99
- # A URL/resource name that uniquely identifies the type of the serialized
100
- # protocol buffer message. This string must contain at least
101
- # one "/" character. The last segment of the URL's path must represent
102
- # the fully qualified name of the type (as in
103
- # `path/google.protobuf.Duration`). The name should be in a canonical form
104
- # (e.g., leading "." is not accepted).
105
- #
106
- # In practice, teams usually precompile into the binary all types that they
107
- # expect it to use in the context of Any. However, for URLs which use the
108
- # scheme `http`, `https`, or no scheme, one can optionally set up a type
109
- # server that maps type URLs to message definitions as follows:
110
- #
111
- # * If no scheme is provided, `https` is assumed.
112
- # * An HTTP GET on the URL must yield a {Google::Protobuf::Type}
113
- # value in binary format, or produce an error.
114
- # * Applications are allowed to cache lookup results based on the
115
- # URL, or have them precompiled into a binary to avoid any
116
- # lookup. Therefore, binary compatibility needs to be preserved
117
- # on changes to types. (Use versioned type names to manage
118
- # breaking changes.)
119
- #
120
- # Note: this functionality is not currently available in the official
121
- # protobuf release, and it is not used for type URLs beginning with
122
- # type.googleapis.com.
123
- #
124
- # Schemes other than `http`, `https` (or the empty scheme) might be
125
- # used with implementation specific semantics.
126
- # @!attribute [rw] value
127
- # @return [String]
128
- # Must be a valid serialized protocol buffer of the above specified type.
129
- class Any; end
130
- end
131
- end
@@ -1,113 +0,0 @@
1
- # Copyright 2020 Google LLC
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # https://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
-
16
- module Google
17
- module Protobuf
18
- # A Timestamp represents a point in time independent of any time zone or local
19
- # calendar, encoded as a count of seconds and fractions of seconds at
20
- # nanosecond resolution. The count is relative to an epoch at UTC midnight on
21
- # January 1, 1970, in the proleptic Gregorian calendar which extends the
22
- # Gregorian calendar backwards to year one.
23
- #
24
- # All minutes are 60 seconds long. Leap seconds are "smeared" so that no leap
25
- # second table is needed for interpretation, using a [24-hour linear
26
- # smear](https://developers.google.com/time/smear).
27
- #
28
- # The range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. By
29
- # restricting to that range, we ensure that we can convert to and from [RFC
30
- # 3339](https://www.ietf.org/rfc/rfc3339.txt) date strings.
31
- #
32
- # = Examples
33
- #
34
- # Example 1: Compute Timestamp from POSIX `time()`.
35
- #
36
- # Timestamp timestamp;
37
- # timestamp.set_seconds(time(NULL));
38
- # timestamp.set_nanos(0);
39
- #
40
- # Example 2: Compute Timestamp from POSIX `gettimeofday()`.
41
- #
42
- # struct timeval tv;
43
- # gettimeofday(&tv, NULL);
44
- #
45
- # Timestamp timestamp;
46
- # timestamp.set_seconds(tv.tv_sec);
47
- # timestamp.set_nanos(tv.tv_usec * 1000);
48
- #
49
- # Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`.
50
- #
51
- # FILETIME ft;
52
- # GetSystemTimeAsFileTime(&ft);
53
- # UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
54
- #
55
- # // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z
56
- # // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z.
57
- # Timestamp timestamp;
58
- # timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL));
59
- # timestamp.set_nanos((INT32) ((ticks % 10000000) * 100));
60
- #
61
- # Example 4: Compute Timestamp from Java `System.currentTimeMillis()`.
62
- #
63
- # long millis = System.currentTimeMillis();
64
- #
65
- # Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000)
66
- # .setNanos((int) ((millis % 1000) * 1000000)).build();
67
- #
68
- #
69
- # Example 5: Compute Timestamp from current time in Python.
70
- #
71
- # timestamp = Timestamp()
72
- # timestamp.GetCurrentTime()
73
- #
74
- # = JSON Mapping
75
- #
76
- # In JSON format, the Timestamp type is encoded as a string in the
77
- # [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the
78
- # format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z"
79
- # where {year} is always expressed using four digits while {month}, {day},
80
- # {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional
81
- # seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution),
82
- # are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone
83
- # is required. A proto3 JSON serializer should always use UTC (as indicated by
84
- # "Z") when printing the Timestamp type and a proto3 JSON parser should be
85
- # able to accept both UTC and other timezones (as indicated by an offset).
86
- #
87
- # For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past
88
- # 01:30 UTC on January 15, 2017.
89
- #
90
- # In JavaScript, one can convert a Date object to this format using the
91
- # standard
92
- # [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString)
93
- # method. In Python, a standard `datetime.datetime` object can be converted
94
- # to this format using
95
- # [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) with
96
- # the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one can use
97
- # the Joda Time's [`ISODateTimeFormat.dateTime()`](
98
- # http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime%2D%2D
99
- # ) to obtain a formatter capable of generating timestamps in this format.
100
- # @!attribute [rw] seconds
101
- # @return [Integer]
102
- # Represents seconds of UTC time since Unix epoch
103
- # 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
104
- # 9999-12-31T23:59:59Z inclusive.
105
- # @!attribute [rw] nanos
106
- # @return [Integer]
107
- # Non-negative fractions of a second at nanosecond resolution. Negative
108
- # second values with fractions must still have non-negative nanos values
109
- # that count forward in time. Must be from 0 to 999,999,999
110
- # inclusive.
111
- class Timestamp; end
112
- end
113
- end
@@ -1,39 +0,0 @@
1
- # Copyright 2020 Google LLC
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # https://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
-
16
- module Google
17
- module Rpc
18
- # The `Status` type defines a logical error model that is suitable for
19
- # different programming environments, including REST APIs and RPC APIs. It is
20
- # used by [gRPC](https://github.com/grpc). Each `Status` message contains
21
- # three pieces of data: error code, error message, and error details.
22
- #
23
- # You can find out more about this error model and how to work with it in the
24
- # [API Design Guide](https://cloud.google.com/apis/design/errors).
25
- # @!attribute [rw] code
26
- # @return [Integer]
27
- # The status code, which should be an enum value of {Google::Rpc::Code}.
28
- # @!attribute [rw] message
29
- # @return [String]
30
- # A developer-facing error message, which should be in English. Any
31
- # user-facing error message should be localized and sent in the
32
- # {Google::Rpc::Status#details} field, or localized by the client.
33
- # @!attribute [rw] details
34
- # @return [Array<Google::Protobuf::Any>]
35
- # A list of messages that carry the error details. There is a common set of
36
- # message types for APIs to use.
37
- class Status; end
38
- end
39
- end
@@ -1,930 +0,0 @@
1
- # Copyright 2020 Google LLC
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # https://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
- #
15
- # EDITING INSTRUCTIONS
16
- # This file was generated from the file
17
- # https://github.com/googleapis/googleapis/blob/master/google/cloud/translate/v3/translation_service.proto,
18
- # and updates to that file get reflected here through a refresh process.
19
- # For the short term, the refresh process will only be runnable by Google
20
- # engineers.
21
-
22
-
23
- require "json"
24
- require "pathname"
25
-
26
- require "google/gax"
27
- require "google/gax/operation"
28
- require "google/longrunning/operations_client"
29
-
30
- require "google/cloud/translate/v3/translation_service_pb"
31
- require "google/cloud/translate/v3/credentials"
32
- require "google/cloud/translate/version"
33
-
34
- module Google
35
- module Cloud
36
- module Translate
37
- module V3
38
- # Provides natural language translation operations.
39
- #
40
- # @!attribute [r] translation_service_stub
41
- # @return [Google::Cloud::Translate::V3::TranslationService::Stub]
42
- class TranslationServiceClient
43
- # @private
44
- attr_reader :translation_service_stub
45
-
46
- # The default address of the service.
47
- SERVICE_ADDRESS = "translate.googleapis.com".freeze
48
-
49
- # The default port of the service.
50
- DEFAULT_SERVICE_PORT = 443
51
-
52
- # The default set of gRPC interceptors.
53
- GRPC_INTERCEPTORS = []
54
-
55
- DEFAULT_TIMEOUT = 30
56
-
57
- PAGE_DESCRIPTORS = {
58
- "list_glossaries" => Google::Gax::PageDescriptor.new(
59
- "page_token",
60
- "next_page_token",
61
- "glossaries")
62
- }.freeze
63
-
64
- private_constant :PAGE_DESCRIPTORS
65
-
66
- # The scopes needed to make gRPC calls to all of the methods defined in
67
- # this service.
68
- ALL_SCOPES = [
69
- "https://www.googleapis.com/auth/cloud-platform",
70
- "https://www.googleapis.com/auth/cloud-translation"
71
- ].freeze
72
-
73
- class OperationsClient < Google::Longrunning::OperationsClient
74
- self::SERVICE_ADDRESS = TranslationServiceClient::SERVICE_ADDRESS
75
- self::GRPC_INTERCEPTORS = TranslationServiceClient::GRPC_INTERCEPTORS
76
- end
77
-
78
- GLOSSARY_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
79
- "projects/{project}/locations/{location}/glossaries/{glossary}"
80
- )
81
-
82
- private_constant :GLOSSARY_PATH_TEMPLATE
83
-
84
- LOCATION_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
85
- "projects/{project}/locations/{location}"
86
- )
87
-
88
- private_constant :LOCATION_PATH_TEMPLATE
89
-
90
- # Returns a fully-qualified glossary resource name string.
91
- # @param project [String]
92
- # @param location [String]
93
- # @param glossary [String]
94
- # @return [String]
95
- def self.glossary_path project, location, glossary
96
- GLOSSARY_PATH_TEMPLATE.render(
97
- :"project" => project,
98
- :"location" => location,
99
- :"glossary" => glossary
100
- )
101
- end
102
-
103
- # Returns a fully-qualified location resource name string.
104
- # @param project [String]
105
- # @param location [String]
106
- # @return [String]
107
- def self.location_path project, location
108
- LOCATION_PATH_TEMPLATE.render(
109
- :"project" => project,
110
- :"location" => location
111
- )
112
- end
113
-
114
- # @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc]
115
- # Provides the means for authenticating requests made by the client. This parameter can
116
- # be many types.
117
- # A `Google::Auth::Credentials` uses a the properties of its represented keyfile for
118
- # authenticating requests made by this client.
119
- # A `String` will be treated as the path to the keyfile to be used for the construction of
120
- # credentials for this client.
121
- # A `Hash` will be treated as the contents of a keyfile to be used for the construction of
122
- # credentials for this client.
123
- # A `GRPC::Core::Channel` will be used to make calls through.
124
- # A `GRPC::Core::ChannelCredentials` for the setting up the RPC client. The channel credentials
125
- # should already be composed with a `GRPC::Core::CallCredentials` object.
126
- # A `Proc` will be used as an updater_proc for the Grpc channel. The proc transforms the
127
- # metadata for requests, generally, to give OAuth credentials.
128
- # @param scopes [Array<String>]
129
- # The OAuth scopes for this service. This parameter is ignored if
130
- # an updater_proc is supplied.
131
- # @param client_config [Hash]
132
- # A Hash for call options for each method. See
133
- # Google::Gax#construct_settings for the structure of
134
- # this data. Falls back to the default config if not specified
135
- # or the specified config is missing data points.
136
- # @param timeout [Numeric]
137
- # The default timeout, in seconds, for calls made through this client.
138
- # @param metadata [Hash]
139
- # Default metadata to be sent with each request. This can be overridden on a per call basis.
140
- # @param service_address [String]
141
- # Override for the service hostname, or `nil` to leave as the default.
142
- # @param service_port [Integer]
143
- # Override for the service port, or `nil` to leave as the default.
144
- # @param exception_transformer [Proc]
145
- # An optional proc that intercepts any exceptions raised during an API call to inject
146
- # custom error handling.
147
- def initialize \
148
- credentials: nil,
149
- scopes: ALL_SCOPES,
150
- client_config: {},
151
- timeout: DEFAULT_TIMEOUT,
152
- metadata: nil,
153
- service_address: nil,
154
- service_port: nil,
155
- exception_transformer: nil,
156
- lib_name: nil,
157
- lib_version: ""
158
- # These require statements are intentionally placed here to initialize
159
- # the gRPC module only when it's required.
160
- # See https://github.com/googleapis/toolkit/issues/446
161
- require "google/gax/grpc"
162
- require "google/cloud/translate/v3/translation_service_services_pb"
163
-
164
- credentials ||= Google::Cloud::Translate::V3::Credentials.default
165
-
166
- @operations_client = OperationsClient.new(
167
- credentials: credentials,
168
- scopes: scopes,
169
- client_config: client_config,
170
- timeout: timeout,
171
- lib_name: lib_name,
172
- service_address: service_address,
173
- service_port: service_port,
174
- lib_version: lib_version,
175
- metadata: metadata,
176
- )
177
-
178
- if credentials.is_a?(String) || credentials.is_a?(Hash)
179
- updater_proc = Google::Cloud::Translate::V3::Credentials.new(credentials).updater_proc
180
- end
181
- if credentials.is_a?(GRPC::Core::Channel)
182
- channel = credentials
183
- end
184
- if credentials.is_a?(GRPC::Core::ChannelCredentials)
185
- chan_creds = credentials
186
- end
187
- if credentials.is_a?(Proc)
188
- updater_proc = credentials
189
- end
190
- if credentials.is_a?(Google::Auth::Credentials)
191
- updater_proc = credentials.updater_proc
192
- end
193
-
194
- package_version = Google::Cloud::Translate::VERSION
195
-
196
- google_api_client = "gl-ruby/#{RUBY_VERSION}"
197
- google_api_client << " #{lib_name}/#{lib_version}" if lib_name
198
- google_api_client << " gapic/#{package_version} gax/#{Google::Gax::VERSION}"
199
- google_api_client << " grpc/#{GRPC::VERSION}"
200
- google_api_client.freeze
201
-
202
- headers = { :"x-goog-api-client" => google_api_client }
203
- if credentials.respond_to?(:quota_project_id) && credentials.quota_project_id
204
- headers[:"x-goog-user-project"] = credentials.quota_project_id
205
- end
206
- headers.merge!(metadata) unless metadata.nil?
207
- client_config_file = Pathname.new(__dir__).join(
208
- "translation_service_client_config.json"
209
- )
210
- defaults = client_config_file.open do |f|
211
- Google::Gax.construct_settings(
212
- "google.cloud.translation.v3.TranslationService",
213
- JSON.parse(f.read),
214
- client_config,
215
- Google::Gax::Grpc::STATUS_CODE_NAMES,
216
- timeout,
217
- page_descriptors: PAGE_DESCRIPTORS,
218
- errors: Google::Gax::Grpc::API_ERRORS,
219
- metadata: headers
220
- )
221
- end
222
-
223
- # Allow overriding the service path/port in subclasses.
224
- service_path = service_address || self.class::SERVICE_ADDRESS
225
- port = service_port || self.class::DEFAULT_SERVICE_PORT
226
- interceptors = self.class::GRPC_INTERCEPTORS
227
- @translation_service_stub = Google::Gax::Grpc.create_stub(
228
- service_path,
229
- port,
230
- chan_creds: chan_creds,
231
- channel: channel,
232
- updater_proc: updater_proc,
233
- scopes: scopes,
234
- interceptors: interceptors,
235
- &Google::Cloud::Translate::V3::TranslationService::Stub.method(:new)
236
- )
237
-
238
- @translate_text = Google::Gax.create_api_call(
239
- @translation_service_stub.method(:translate_text),
240
- defaults["translate_text"],
241
- exception_transformer: exception_transformer,
242
- params_extractor: proc do |request|
243
- {'parent' => request.parent}
244
- end
245
- )
246
- @detect_language = Google::Gax.create_api_call(
247
- @translation_service_stub.method(:detect_language),
248
- defaults["detect_language"],
249
- exception_transformer: exception_transformer,
250
- params_extractor: proc do |request|
251
- {'parent' => request.parent}
252
- end
253
- )
254
- @get_supported_languages = Google::Gax.create_api_call(
255
- @translation_service_stub.method(:get_supported_languages),
256
- defaults["get_supported_languages"],
257
- exception_transformer: exception_transformer,
258
- params_extractor: proc do |request|
259
- {'parent' => request.parent}
260
- end
261
- )
262
- @batch_translate_text = Google::Gax.create_api_call(
263
- @translation_service_stub.method(:batch_translate_text),
264
- defaults["batch_translate_text"],
265
- exception_transformer: exception_transformer,
266
- params_extractor: proc do |request|
267
- {'parent' => request.parent}
268
- end
269
- )
270
- @create_glossary = Google::Gax.create_api_call(
271
- @translation_service_stub.method(:create_glossary),
272
- defaults["create_glossary"],
273
- exception_transformer: exception_transformer,
274
- params_extractor: proc do |request|
275
- {'parent' => request.parent}
276
- end
277
- )
278
- @list_glossaries = Google::Gax.create_api_call(
279
- @translation_service_stub.method(:list_glossaries),
280
- defaults["list_glossaries"],
281
- exception_transformer: exception_transformer,
282
- params_extractor: proc do |request|
283
- {'parent' => request.parent}
284
- end
285
- )
286
- @get_glossary = Google::Gax.create_api_call(
287
- @translation_service_stub.method(:get_glossary),
288
- defaults["get_glossary"],
289
- exception_transformer: exception_transformer,
290
- params_extractor: proc do |request|
291
- {'name' => request.name}
292
- end
293
- )
294
- @delete_glossary = Google::Gax.create_api_call(
295
- @translation_service_stub.method(:delete_glossary),
296
- defaults["delete_glossary"],
297
- exception_transformer: exception_transformer,
298
- params_extractor: proc do |request|
299
- {'name' => request.name}
300
- end
301
- )
302
- end
303
-
304
- # Service calls
305
-
306
- # Translates input text and returns translated text.
307
- #
308
- # @param contents [Array<String>]
309
- # Required. The content of the input in string format.
310
- # We recommend the total content be less than 30k codepoints.
311
- # Use BatchTranslateText for larger text.
312
- # @param target_language_code [String]
313
- # Required. The BCP-47 language code to use for translation of the input
314
- # text, set to one of the language codes listed in Language Support.
315
- # @param parent [String]
316
- # Required. Project or location to make a call. Must refer to a caller's
317
- # project.
318
- #
319
- # Format: `projects/{project-number-or-id}` or
320
- # `projects/{project-number-or-id}/locations/{location-id}`.
321
- #
322
- # For global calls, use `projects/{project-number-or-id}/locations/global` or
323
- # `projects/{project-number-or-id}`.
324
- #
325
- # Non-global location is required for requests using AutoML models or
326
- # custom glossaries.
327
- #
328
- # Models and glossaries must be within the same region (have same
329
- # location-id), otherwise an INVALID_ARGUMENT (400) error is returned.
330
- # @param mime_type [String]
331
- # Optional. The format of the source text, for example, "text/html",
332
- # "text/plain". If left blank, the MIME type defaults to "text/html".
333
- # @param source_language_code [String]
334
- # Optional. The BCP-47 language code of the input text if
335
- # known, for example, "en-US" or "sr-Latn". Supported language codes are
336
- # listed in Language Support. If the source language isn't specified, the API
337
- # attempts to identify the source language automatically and returns the
338
- # source language within the response.
339
- # @param model [String]
340
- # Optional. The `model` type requested for this translation.
341
- #
342
- # The format depends on model type:
343
- #
344
- # * AutoML Translation models:
345
- # `projects/{project-number-or-id}/locations/{location-id}/models/{model-id}`
346
- #
347
- # * General (built-in) models:
348
- # `projects/{project-number-or-id}/locations/{location-id}/models/general/nmt`,
349
- # `projects/{project-number-or-id}/locations/{location-id}/models/general/base`
350
- #
351
- #
352
- # For global (non-regionalized) requests, use `location-id` `global`.
353
- # For example,
354
- # `projects/{project-number-or-id}/locations/global/models/general/nmt`.
355
- #
356
- # If missing, the system decides which google base model to use.
357
- # @param glossary_config [Google::Cloud::Translate::V3::TranslateTextGlossaryConfig | Hash]
358
- # Optional. Glossary to be applied. The glossary must be
359
- # within the same region (have the same location-id) as the model, otherwise
360
- # an INVALID_ARGUMENT (400) error is returned.
361
- # A hash of the same form as `Google::Cloud::Translate::V3::TranslateTextGlossaryConfig`
362
- # can also be provided.
363
- # @param labels [Hash{String => String}]
364
- # Optional. The labels with user-defined metadata for the request.
365
- #
366
- # Label keys and values can be no longer than 63 characters
367
- # (Unicode codepoints), can only contain lowercase letters, numeric
368
- # characters, underscores and dashes. International characters are allowed.
369
- # Label values are optional. Label keys must start with a letter.
370
- #
371
- # See https://cloud.google.com/translate/docs/labels for more information.
372
- # @param options [Google::Gax::CallOptions]
373
- # Overrides the default settings for this call, e.g, timeout,
374
- # retries, etc.
375
- # @yield [result, operation] Access the result along with the RPC operation
376
- # @yieldparam result [Google::Cloud::Translate::V3::TranslateTextResponse]
377
- # @yieldparam operation [GRPC::ActiveCall::Operation]
378
- # @return [Google::Cloud::Translate::V3::TranslateTextResponse]
379
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
380
- # @example
381
- # require "google/cloud/translate"
382
- #
383
- # translation_client = Google::Cloud::Translate.new(version: :v3)
384
- #
385
- # # TODO: Initialize `contents`:
386
- # contents = []
387
- #
388
- # # TODO: Initialize `target_language_code`:
389
- # target_language_code = ''
390
- # formatted_parent = Google::Cloud::Translate::V3::TranslationServiceClient.location_path("[PROJECT]", "[LOCATION]")
391
- # response = translation_client.translate_text(contents, target_language_code, formatted_parent)
392
-
393
- def translate_text \
394
- contents,
395
- target_language_code,
396
- parent,
397
- mime_type: nil,
398
- source_language_code: nil,
399
- model: nil,
400
- glossary_config: nil,
401
- labels: nil,
402
- options: nil,
403
- &block
404
- req = {
405
- contents: contents,
406
- target_language_code: target_language_code,
407
- parent: parent,
408
- mime_type: mime_type,
409
- source_language_code: source_language_code,
410
- model: model,
411
- glossary_config: glossary_config,
412
- labels: labels
413
- }.delete_if { |_, v| v.nil? }
414
- req = Google::Gax::to_proto(req, Google::Cloud::Translate::V3::TranslateTextRequest)
415
- @translate_text.call(req, options, &block)
416
- end
417
-
418
- # Detects the language of text within a request.
419
- #
420
- # @param parent [String]
421
- # Required. Project or location to make a call. Must refer to a caller's
422
- # project.
423
- #
424
- # Format: `projects/{project-number-or-id}/locations/{location-id}` or
425
- # `projects/{project-number-or-id}`.
426
- #
427
- # For global calls, use `projects/{project-number-or-id}/locations/global` or
428
- # `projects/{project-number-or-id}`.
429
- #
430
- # Only models within the same region (has same location-id) can be used.
431
- # Otherwise an INVALID_ARGUMENT (400) error is returned.
432
- # @param model [String]
433
- # Optional. The language detection model to be used.
434
- #
435
- # Format:
436
- # `projects/{project-number-or-id}/locations/{location-id}/models/language-detection/{model-id}`
437
- #
438
- # Only one language detection model is currently supported:
439
- # `projects/{project-number-or-id}/locations/{location-id}/models/language-detection/default`.
440
- #
441
- # If not specified, the default model is used.
442
- # @param content [String]
443
- # The content of the input stored as a string.
444
- # @param mime_type [String]
445
- # Optional. The format of the source text, for example, "text/html",
446
- # "text/plain". If left blank, the MIME type defaults to "text/html".
447
- # @param labels [Hash{String => String}]
448
- # Optional. The labels with user-defined metadata for the request.
449
- #
450
- # Label keys and values can be no longer than 63 characters
451
- # (Unicode codepoints), can only contain lowercase letters, numeric
452
- # characters, underscores and dashes. International characters are allowed.
453
- # Label values are optional. Label keys must start with a letter.
454
- #
455
- # See https://cloud.google.com/translate/docs/labels for more information.
456
- # @param options [Google::Gax::CallOptions]
457
- # Overrides the default settings for this call, e.g, timeout,
458
- # retries, etc.
459
- # @yield [result, operation] Access the result along with the RPC operation
460
- # @yieldparam result [Google::Cloud::Translate::V3::DetectLanguageResponse]
461
- # @yieldparam operation [GRPC::ActiveCall::Operation]
462
- # @return [Google::Cloud::Translate::V3::DetectLanguageResponse]
463
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
464
- # @example
465
- # require "google/cloud/translate"
466
- #
467
- # translation_client = Google::Cloud::Translate.new(version: :v3)
468
- # formatted_parent = Google::Cloud::Translate::V3::TranslationServiceClient.location_path("[PROJECT]", "[LOCATION]")
469
- # response = translation_client.detect_language(formatted_parent)
470
-
471
- def detect_language \
472
- parent,
473
- model: nil,
474
- content: nil,
475
- mime_type: nil,
476
- labels: nil,
477
- options: nil,
478
- &block
479
- req = {
480
- parent: parent,
481
- model: model,
482
- content: content,
483
- mime_type: mime_type,
484
- labels: labels
485
- }.delete_if { |_, v| v.nil? }
486
- req = Google::Gax::to_proto(req, Google::Cloud::Translate::V3::DetectLanguageRequest)
487
- @detect_language.call(req, options, &block)
488
- end
489
-
490
- # Returns a list of supported languages for translation.
491
- #
492
- # @param parent [String]
493
- # Required. Project or location to make a call. Must refer to a caller's
494
- # project.
495
- #
496
- # Format: `projects/{project-number-or-id}` or
497
- # `projects/{project-number-or-id}/locations/{location-id}`.
498
- #
499
- # For global calls, use `projects/{project-number-or-id}/locations/global` or
500
- # `projects/{project-number-or-id}`.
501
- #
502
- # Non-global location is required for AutoML models.
503
- #
504
- # Only models within the same region (have same location-id) can be used,
505
- # otherwise an INVALID_ARGUMENT (400) error is returned.
506
- # @param display_language_code [String]
507
- # Optional. The language to use to return localized, human readable names
508
- # of supported languages. If missing, then display names are not returned
509
- # in a response.
510
- # @param model [String]
511
- # Optional. Get supported languages of this model.
512
- #
513
- # The format depends on model type:
514
- #
515
- # * AutoML Translation models:
516
- # `projects/{project-number-or-id}/locations/{location-id}/models/{model-id}`
517
- #
518
- # * General (built-in) models:
519
- # `projects/{project-number-or-id}/locations/{location-id}/models/general/nmt`,
520
- # `projects/{project-number-or-id}/locations/{location-id}/models/general/base`
521
- #
522
- #
523
- # Returns languages supported by the specified model.
524
- # If missing, we get supported languages of Google general base (PBMT) model.
525
- # @param options [Google::Gax::CallOptions]
526
- # Overrides the default settings for this call, e.g, timeout,
527
- # retries, etc.
528
- # @yield [result, operation] Access the result along with the RPC operation
529
- # @yieldparam result [Google::Cloud::Translate::V3::SupportedLanguages]
530
- # @yieldparam operation [GRPC::ActiveCall::Operation]
531
- # @return [Google::Cloud::Translate::V3::SupportedLanguages]
532
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
533
- # @example
534
- # require "google/cloud/translate"
535
- #
536
- # translation_client = Google::Cloud::Translate.new(version: :v3)
537
- # formatted_parent = Google::Cloud::Translate::V3::TranslationServiceClient.location_path("[PROJECT]", "[LOCATION]")
538
- # response = translation_client.get_supported_languages(formatted_parent)
539
-
540
- def get_supported_languages \
541
- parent,
542
- display_language_code: nil,
543
- model: nil,
544
- options: nil,
545
- &block
546
- req = {
547
- parent: parent,
548
- display_language_code: display_language_code,
549
- model: model
550
- }.delete_if { |_, v| v.nil? }
551
- req = Google::Gax::to_proto(req, Google::Cloud::Translate::V3::GetSupportedLanguagesRequest)
552
- @get_supported_languages.call(req, options, &block)
553
- end
554
-
555
- # Translates a large volume of text in asynchronous batch mode.
556
- # This function provides real-time output as the inputs are being processed.
557
- # If caller cancels a request, the partial results (for an input file, it's
558
- # all or nothing) may still be available on the specified output location.
559
- #
560
- # This call returns immediately and you can
561
- # use google.longrunning.Operation.name to poll the status of the call.
562
- #
563
- # @param parent [String]
564
- # Required. Location to make a call. Must refer to a caller's project.
565
- #
566
- # Format: `projects/{project-number-or-id}/locations/{location-id}`.
567
- #
568
- # The `global` location is not supported for batch translation.
569
- #
570
- # Only AutoML Translation models or glossaries within the same region (have
571
- # the same location-id) can be used, otherwise an INVALID_ARGUMENT (400)
572
- # error is returned.
573
- # @param source_language_code [String]
574
- # Required. Source language code.
575
- # @param target_language_codes [Array<String>]
576
- # Required. Specify up to 10 language codes here.
577
- # @param input_configs [Array<Google::Cloud::Translate::V3::InputConfig | Hash>]
578
- # Required. Input configurations.
579
- # The total number of files matched should be <= 1000.
580
- # The total content size should be <= 100M Unicode codepoints.
581
- # The files must use UTF-8 encoding.
582
- # A hash of the same form as `Google::Cloud::Translate::V3::InputConfig`
583
- # can also be provided.
584
- # @param output_config [Google::Cloud::Translate::V3::OutputConfig | Hash]
585
- # Required. Output configuration.
586
- # If 2 input configs match to the same file (that is, same input path),
587
- # we don't generate output for duplicate inputs.
588
- # A hash of the same form as `Google::Cloud::Translate::V3::OutputConfig`
589
- # can also be provided.
590
- # @param models [Hash{String => String}]
591
- # Optional. The models to use for translation. Map's key is target language
592
- # code. Map's value is model name. Value can be a built-in general model,
593
- # or an AutoML Translation model.
594
- #
595
- # The value format depends on model type:
596
- #
597
- # * AutoML Translation models:
598
- # `projects/{project-number-or-id}/locations/{location-id}/models/{model-id}`
599
- #
600
- # * General (built-in) models:
601
- # `projects/{project-number-or-id}/locations/{location-id}/models/general/nmt`,
602
- # `projects/{project-number-or-id}/locations/{location-id}/models/general/base`
603
- #
604
- #
605
- # If the map is empty or a specific model is
606
- # not requested for a language pair, then default google model (nmt) is used.
607
- # @param glossaries [Hash{String => Google::Cloud::Translate::V3::TranslateTextGlossaryConfig | Hash}]
608
- # Optional. Glossaries to be applied for translation.
609
- # It's keyed by target language code.
610
- # A hash of the same form as `Google::Cloud::Translate::V3::TranslateTextGlossaryConfig`
611
- # can also be provided.
612
- # @param labels [Hash{String => String}]
613
- # Optional. The labels with user-defined metadata for the request.
614
- #
615
- # Label keys and values can be no longer than 63 characters
616
- # (Unicode codepoints), can only contain lowercase letters, numeric
617
- # characters, underscores and dashes. International characters are allowed.
618
- # Label values are optional. Label keys must start with a letter.
619
- #
620
- # See https://cloud.google.com/translate/docs/labels for more information.
621
- # @param options [Google::Gax::CallOptions]
622
- # Overrides the default settings for this call, e.g, timeout,
623
- # retries, etc.
624
- # @return [Google::Gax::Operation]
625
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
626
- # @example
627
- # require "google/cloud/translate"
628
- #
629
- # translation_client = Google::Cloud::Translate.new(version: :v3)
630
- # formatted_parent = Google::Cloud::Translate::V3::TranslationServiceClient.location_path("[PROJECT]", "[LOCATION]")
631
- #
632
- # # TODO: Initialize `source_language_code`:
633
- # source_language_code = ''
634
- #
635
- # # TODO: Initialize `target_language_codes`:
636
- # target_language_codes = []
637
- #
638
- # # TODO: Initialize `input_configs`:
639
- # input_configs = []
640
- #
641
- # # TODO: Initialize `output_config`:
642
- # output_config = {}
643
- #
644
- # # Register a callback during the method call.
645
- # operation = translation_client.batch_translate_text(formatted_parent, source_language_code, target_language_codes, input_configs, output_config) do |op|
646
- # raise op.results.message if op.error?
647
- # op_results = op.results
648
- # # Process the results.
649
- #
650
- # metadata = op.metadata
651
- # # Process the metadata.
652
- # end
653
- #
654
- # # Or use the return value to register a callback.
655
- # operation.on_done do |op|
656
- # raise op.results.message if op.error?
657
- # op_results = op.results
658
- # # Process the results.
659
- #
660
- # metadata = op.metadata
661
- # # Process the metadata.
662
- # end
663
- #
664
- # # Manually reload the operation.
665
- # operation.reload!
666
- #
667
- # # Or block until the operation completes, triggering callbacks on
668
- # # completion.
669
- # operation.wait_until_done!
670
-
671
- def batch_translate_text \
672
- parent,
673
- source_language_code,
674
- target_language_codes,
675
- input_configs,
676
- output_config,
677
- models: nil,
678
- glossaries: nil,
679
- labels: nil,
680
- options: nil
681
- req = {
682
- parent: parent,
683
- source_language_code: source_language_code,
684
- target_language_codes: target_language_codes,
685
- input_configs: input_configs,
686
- output_config: output_config,
687
- models: models,
688
- glossaries: glossaries,
689
- labels: labels
690
- }.delete_if { |_, v| v.nil? }
691
- req = Google::Gax::to_proto(req, Google::Cloud::Translate::V3::BatchTranslateTextRequest)
692
- operation = Google::Gax::Operation.new(
693
- @batch_translate_text.call(req, options),
694
- @operations_client,
695
- Google::Cloud::Translate::V3::BatchTranslateResponse,
696
- Google::Cloud::Translate::V3::BatchTranslateMetadata,
697
- call_options: options
698
- )
699
- operation.on_done { |operation| yield(operation) } if block_given?
700
- operation
701
- end
702
-
703
- # Creates a glossary and returns the long-running operation. Returns
704
- # NOT_FOUND, if the project doesn't exist.
705
- #
706
- # @param parent [String]
707
- # Required. The project name.
708
- # @param glossary [Google::Cloud::Translate::V3::Glossary | Hash]
709
- # Required. The glossary to create.
710
- # A hash of the same form as `Google::Cloud::Translate::V3::Glossary`
711
- # can also be provided.
712
- # @param options [Google::Gax::CallOptions]
713
- # Overrides the default settings for this call, e.g, timeout,
714
- # retries, etc.
715
- # @return [Google::Gax::Operation]
716
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
717
- # @example
718
- # require "google/cloud/translate"
719
- #
720
- # translation_client = Google::Cloud::Translate.new(version: :v3)
721
- # formatted_parent = Google::Cloud::Translate::V3::TranslationServiceClient.location_path("[PROJECT]", "[LOCATION]")
722
- #
723
- # # TODO: Initialize `glossary`:
724
- # glossary = {}
725
- #
726
- # # Register a callback during the method call.
727
- # operation = translation_client.create_glossary(formatted_parent, glossary) do |op|
728
- # raise op.results.message if op.error?
729
- # op_results = op.results
730
- # # Process the results.
731
- #
732
- # metadata = op.metadata
733
- # # Process the metadata.
734
- # end
735
- #
736
- # # Or use the return value to register a callback.
737
- # operation.on_done do |op|
738
- # raise op.results.message if op.error?
739
- # op_results = op.results
740
- # # Process the results.
741
- #
742
- # metadata = op.metadata
743
- # # Process the metadata.
744
- # end
745
- #
746
- # # Manually reload the operation.
747
- # operation.reload!
748
- #
749
- # # Or block until the operation completes, triggering callbacks on
750
- # # completion.
751
- # operation.wait_until_done!
752
-
753
- def create_glossary \
754
- parent,
755
- glossary,
756
- options: nil
757
- req = {
758
- parent: parent,
759
- glossary: glossary
760
- }.delete_if { |_, v| v.nil? }
761
- req = Google::Gax::to_proto(req, Google::Cloud::Translate::V3::CreateGlossaryRequest)
762
- operation = Google::Gax::Operation.new(
763
- @create_glossary.call(req, options),
764
- @operations_client,
765
- Google::Cloud::Translate::V3::Glossary,
766
- Google::Cloud::Translate::V3::CreateGlossaryMetadata,
767
- call_options: options
768
- )
769
- operation.on_done { |operation| yield(operation) } if block_given?
770
- operation
771
- end
772
-
773
- # Lists glossaries in a project. Returns NOT_FOUND, if the project doesn't
774
- # exist.
775
- #
776
- # @param parent [String]
777
- # Required. The name of the project from which to list all of the glossaries.
778
- # @param page_size [Integer]
779
- # The maximum number of resources contained in the underlying API
780
- # response. If page streaming is performed per-resource, this
781
- # parameter does not affect the return value. If page streaming is
782
- # performed per-page, this determines the maximum number of
783
- # resources in a page.
784
- # @param filter [String]
785
- # Optional. Filter specifying constraints of a list operation.
786
- # Filtering is not supported yet, and the parameter currently has no effect.
787
- # If missing, no filtering is performed.
788
- # @param options [Google::Gax::CallOptions]
789
- # Overrides the default settings for this call, e.g, timeout,
790
- # retries, etc.
791
- # @yield [result, operation] Access the result along with the RPC operation
792
- # @yieldparam result [Google::Gax::PagedEnumerable<Google::Cloud::Translate::V3::Glossary>]
793
- # @yieldparam operation [GRPC::ActiveCall::Operation]
794
- # @return [Google::Gax::PagedEnumerable<Google::Cloud::Translate::V3::Glossary>]
795
- # An enumerable of Google::Cloud::Translate::V3::Glossary instances.
796
- # See Google::Gax::PagedEnumerable documentation for other
797
- # operations such as per-page iteration or access to the response
798
- # object.
799
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
800
- # @example
801
- # require "google/cloud/translate"
802
- #
803
- # translation_client = Google::Cloud::Translate.new(version: :v3)
804
- # formatted_parent = Google::Cloud::Translate::V3::TranslationServiceClient.location_path("[PROJECT]", "[LOCATION]")
805
- #
806
- # # Iterate over all results.
807
- # translation_client.list_glossaries(formatted_parent).each do |element|
808
- # # Process element.
809
- # end
810
- #
811
- # # Or iterate over results one page at a time.
812
- # translation_client.list_glossaries(formatted_parent).each_page do |page|
813
- # # Process each page at a time.
814
- # page.each do |element|
815
- # # Process element.
816
- # end
817
- # end
818
-
819
- def list_glossaries \
820
- parent,
821
- page_size: nil,
822
- filter: nil,
823
- options: nil,
824
- &block
825
- req = {
826
- parent: parent,
827
- page_size: page_size,
828
- filter: filter
829
- }.delete_if { |_, v| v.nil? }
830
- req = Google::Gax::to_proto(req, Google::Cloud::Translate::V3::ListGlossariesRequest)
831
- @list_glossaries.call(req, options, &block)
832
- end
833
-
834
- # Gets a glossary. Returns NOT_FOUND, if the glossary doesn't
835
- # exist.
836
- #
837
- # @param name [String]
838
- # Required. The name of the glossary to retrieve.
839
- # @param options [Google::Gax::CallOptions]
840
- # Overrides the default settings for this call, e.g, timeout,
841
- # retries, etc.
842
- # @yield [result, operation] Access the result along with the RPC operation
843
- # @yieldparam result [Google::Cloud::Translate::V3::Glossary]
844
- # @yieldparam operation [GRPC::ActiveCall::Operation]
845
- # @return [Google::Cloud::Translate::V3::Glossary]
846
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
847
- # @example
848
- # require "google/cloud/translate"
849
- #
850
- # translation_client = Google::Cloud::Translate.new(version: :v3)
851
- # formatted_name = Google::Cloud::Translate::V3::TranslationServiceClient.glossary_path("[PROJECT]", "[LOCATION]", "[GLOSSARY]")
852
- # response = translation_client.get_glossary(formatted_name)
853
-
854
- def get_glossary \
855
- name,
856
- options: nil,
857
- &block
858
- req = {
859
- name: name
860
- }.delete_if { |_, v| v.nil? }
861
- req = Google::Gax::to_proto(req, Google::Cloud::Translate::V3::GetGlossaryRequest)
862
- @get_glossary.call(req, options, &block)
863
- end
864
-
865
- # Deletes a glossary, or cancels glossary construction
866
- # if the glossary isn't created yet.
867
- # Returns NOT_FOUND, if the glossary doesn't exist.
868
- #
869
- # @param name [String]
870
- # Required. The name of the glossary to delete.
871
- # @param options [Google::Gax::CallOptions]
872
- # Overrides the default settings for this call, e.g, timeout,
873
- # retries, etc.
874
- # @return [Google::Gax::Operation]
875
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
876
- # @example
877
- # require "google/cloud/translate"
878
- #
879
- # translation_client = Google::Cloud::Translate.new(version: :v3)
880
- # formatted_name = Google::Cloud::Translate::V3::TranslationServiceClient.glossary_path("[PROJECT]", "[LOCATION]", "[GLOSSARY]")
881
- #
882
- # # Register a callback during the method call.
883
- # operation = translation_client.delete_glossary(formatted_name) do |op|
884
- # raise op.results.message if op.error?
885
- # op_results = op.results
886
- # # Process the results.
887
- #
888
- # metadata = op.metadata
889
- # # Process the metadata.
890
- # end
891
- #
892
- # # Or use the return value to register a callback.
893
- # operation.on_done do |op|
894
- # raise op.results.message if op.error?
895
- # op_results = op.results
896
- # # Process the results.
897
- #
898
- # metadata = op.metadata
899
- # # Process the metadata.
900
- # end
901
- #
902
- # # Manually reload the operation.
903
- # operation.reload!
904
- #
905
- # # Or block until the operation completes, triggering callbacks on
906
- # # completion.
907
- # operation.wait_until_done!
908
-
909
- def delete_glossary \
910
- name,
911
- options: nil
912
- req = {
913
- name: name
914
- }.delete_if { |_, v| v.nil? }
915
- req = Google::Gax::to_proto(req, Google::Cloud::Translate::V3::DeleteGlossaryRequest)
916
- operation = Google::Gax::Operation.new(
917
- @delete_glossary.call(req, options),
918
- @operations_client,
919
- Google::Cloud::Translate::V3::DeleteGlossaryResponse,
920
- Google::Cloud::Translate::V3::DeleteGlossaryMetadata,
921
- call_options: options
922
- )
923
- operation.on_done { |operation| yield(operation) } if block_given?
924
- operation
925
- end
926
- end
927
- end
928
- end
929
- end
930
- end