google-cloud-translate 2.1.2 → 3.0.2

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 +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 -152
  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 -927
  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,927 +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
- headers.merge!(metadata) unless metadata.nil?
204
- client_config_file = Pathname.new(__dir__).join(
205
- "translation_service_client_config.json"
206
- )
207
- defaults = client_config_file.open do |f|
208
- Google::Gax.construct_settings(
209
- "google.cloud.translation.v3.TranslationService",
210
- JSON.parse(f.read),
211
- client_config,
212
- Google::Gax::Grpc::STATUS_CODE_NAMES,
213
- timeout,
214
- page_descriptors: PAGE_DESCRIPTORS,
215
- errors: Google::Gax::Grpc::API_ERRORS,
216
- metadata: headers
217
- )
218
- end
219
-
220
- # Allow overriding the service path/port in subclasses.
221
- service_path = service_address || self.class::SERVICE_ADDRESS
222
- port = service_port || self.class::DEFAULT_SERVICE_PORT
223
- interceptors = self.class::GRPC_INTERCEPTORS
224
- @translation_service_stub = Google::Gax::Grpc.create_stub(
225
- service_path,
226
- port,
227
- chan_creds: chan_creds,
228
- channel: channel,
229
- updater_proc: updater_proc,
230
- scopes: scopes,
231
- interceptors: interceptors,
232
- &Google::Cloud::Translate::V3::TranslationService::Stub.method(:new)
233
- )
234
-
235
- @translate_text = Google::Gax.create_api_call(
236
- @translation_service_stub.method(:translate_text),
237
- defaults["translate_text"],
238
- exception_transformer: exception_transformer,
239
- params_extractor: proc do |request|
240
- {'parent' => request.parent}
241
- end
242
- )
243
- @detect_language = Google::Gax.create_api_call(
244
- @translation_service_stub.method(:detect_language),
245
- defaults["detect_language"],
246
- exception_transformer: exception_transformer,
247
- params_extractor: proc do |request|
248
- {'parent' => request.parent}
249
- end
250
- )
251
- @get_supported_languages = Google::Gax.create_api_call(
252
- @translation_service_stub.method(:get_supported_languages),
253
- defaults["get_supported_languages"],
254
- exception_transformer: exception_transformer,
255
- params_extractor: proc do |request|
256
- {'parent' => request.parent}
257
- end
258
- )
259
- @batch_translate_text = Google::Gax.create_api_call(
260
- @translation_service_stub.method(:batch_translate_text),
261
- defaults["batch_translate_text"],
262
- exception_transformer: exception_transformer,
263
- params_extractor: proc do |request|
264
- {'parent' => request.parent}
265
- end
266
- )
267
- @create_glossary = Google::Gax.create_api_call(
268
- @translation_service_stub.method(:create_glossary),
269
- defaults["create_glossary"],
270
- exception_transformer: exception_transformer,
271
- params_extractor: proc do |request|
272
- {'parent' => request.parent}
273
- end
274
- )
275
- @list_glossaries = Google::Gax.create_api_call(
276
- @translation_service_stub.method(:list_glossaries),
277
- defaults["list_glossaries"],
278
- exception_transformer: exception_transformer,
279
- params_extractor: proc do |request|
280
- {'parent' => request.parent}
281
- end
282
- )
283
- @get_glossary = Google::Gax.create_api_call(
284
- @translation_service_stub.method(:get_glossary),
285
- defaults["get_glossary"],
286
- exception_transformer: exception_transformer,
287
- params_extractor: proc do |request|
288
- {'name' => request.name}
289
- end
290
- )
291
- @delete_glossary = Google::Gax.create_api_call(
292
- @translation_service_stub.method(:delete_glossary),
293
- defaults["delete_glossary"],
294
- exception_transformer: exception_transformer,
295
- params_extractor: proc do |request|
296
- {'name' => request.name}
297
- end
298
- )
299
- end
300
-
301
- # Service calls
302
-
303
- # Translates input text and returns translated text.
304
- #
305
- # @param contents [Array<String>]
306
- # Required. The content of the input in string format.
307
- # We recommend the total content be less than 30k codepoints.
308
- # Use BatchTranslateText for larger text.
309
- # @param target_language_code [String]
310
- # Required. The BCP-47 language code to use for translation of the input
311
- # text, set to one of the language codes listed in Language Support.
312
- # @param parent [String]
313
- # Required. Project or location to make a call. Must refer to a caller's
314
- # project.
315
- #
316
- # Format: `projects/{project-number-or-id}` or
317
- # `projects/{project-number-or-id}/locations/{location-id}`.
318
- #
319
- # For global calls, use `projects/{project-number-or-id}/locations/global` or
320
- # `projects/{project-number-or-id}`.
321
- #
322
- # Non-global location is required for requests using AutoML models or
323
- # custom glossaries.
324
- #
325
- # Models and glossaries must be within the same region (have same
326
- # location-id), otherwise an INVALID_ARGUMENT (400) error is returned.
327
- # @param mime_type [String]
328
- # Optional. The format of the source text, for example, "text/html",
329
- # "text/plain". If left blank, the MIME type defaults to "text/html".
330
- # @param source_language_code [String]
331
- # Optional. The BCP-47 language code of the input text if
332
- # known, for example, "en-US" or "sr-Latn". Supported language codes are
333
- # listed in Language Support. If the source language isn't specified, the API
334
- # attempts to identify the source language automatically and returns the
335
- # source language within the response.
336
- # @param model [String]
337
- # Optional. The `model` type requested for this translation.
338
- #
339
- # The format depends on model type:
340
- #
341
- # * AutoML Translation models:
342
- # `projects/{project-number-or-id}/locations/{location-id}/models/{model-id}`
343
- #
344
- # * General (built-in) models:
345
- # `projects/{project-number-or-id}/locations/{location-id}/models/general/nmt`,
346
- # `projects/{project-number-or-id}/locations/{location-id}/models/general/base`
347
- #
348
- #
349
- # For global (non-regionalized) requests, use `location-id` `global`.
350
- # For example,
351
- # `projects/{project-number-or-id}/locations/global/models/general/nmt`.
352
- #
353
- # If missing, the system decides which google base model to use.
354
- # @param glossary_config [Google::Cloud::Translate::V3::TranslateTextGlossaryConfig | Hash]
355
- # Optional. Glossary to be applied. The glossary must be
356
- # within the same region (have the same location-id) as the model, otherwise
357
- # an INVALID_ARGUMENT (400) error is returned.
358
- # A hash of the same form as `Google::Cloud::Translate::V3::TranslateTextGlossaryConfig`
359
- # can also be provided.
360
- # @param labels [Hash{String => String}]
361
- # Optional. The labels with user-defined metadata for the request.
362
- #
363
- # Label keys and values can be no longer than 63 characters
364
- # (Unicode codepoints), can only contain lowercase letters, numeric
365
- # characters, underscores and dashes. International characters are allowed.
366
- # Label values are optional. Label keys must start with a letter.
367
- #
368
- # See https://cloud.google.com/translate/docs/labels for more information.
369
- # @param options [Google::Gax::CallOptions]
370
- # Overrides the default settings for this call, e.g, timeout,
371
- # retries, etc.
372
- # @yield [result, operation] Access the result along with the RPC operation
373
- # @yieldparam result [Google::Cloud::Translate::V3::TranslateTextResponse]
374
- # @yieldparam operation [GRPC::ActiveCall::Operation]
375
- # @return [Google::Cloud::Translate::V3::TranslateTextResponse]
376
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
377
- # @example
378
- # require "google/cloud/translate"
379
- #
380
- # translation_client = Google::Cloud::Translate.new(version: :v3)
381
- #
382
- # # TODO: Initialize `contents`:
383
- # contents = []
384
- #
385
- # # TODO: Initialize `target_language_code`:
386
- # target_language_code = ''
387
- # formatted_parent = Google::Cloud::Translate::V3::TranslationServiceClient.location_path("[PROJECT]", "[LOCATION]")
388
- # response = translation_client.translate_text(contents, target_language_code, formatted_parent)
389
-
390
- def translate_text \
391
- contents,
392
- target_language_code,
393
- parent,
394
- mime_type: nil,
395
- source_language_code: nil,
396
- model: nil,
397
- glossary_config: nil,
398
- labels: nil,
399
- options: nil,
400
- &block
401
- req = {
402
- contents: contents,
403
- target_language_code: target_language_code,
404
- parent: parent,
405
- mime_type: mime_type,
406
- source_language_code: source_language_code,
407
- model: model,
408
- glossary_config: glossary_config,
409
- labels: labels
410
- }.delete_if { |_, v| v.nil? }
411
- req = Google::Gax::to_proto(req, Google::Cloud::Translate::V3::TranslateTextRequest)
412
- @translate_text.call(req, options, &block)
413
- end
414
-
415
- # Detects the language of text within a request.
416
- #
417
- # @param parent [String]
418
- # Required. Project or location to make a call. Must refer to a caller's
419
- # project.
420
- #
421
- # Format: `projects/{project-number-or-id}/locations/{location-id}` or
422
- # `projects/{project-number-or-id}`.
423
- #
424
- # For global calls, use `projects/{project-number-or-id}/locations/global` or
425
- # `projects/{project-number-or-id}`.
426
- #
427
- # Only models within the same region (has same location-id) can be used.
428
- # Otherwise an INVALID_ARGUMENT (400) error is returned.
429
- # @param model [String]
430
- # Optional. The language detection model to be used.
431
- #
432
- # Format:
433
- # `projects/{project-number-or-id}/locations/{location-id}/models/language-detection/{model-id}`
434
- #
435
- # Only one language detection model is currently supported:
436
- # `projects/{project-number-or-id}/locations/{location-id}/models/language-detection/default`.
437
- #
438
- # If not specified, the default model is used.
439
- # @param content [String]
440
- # The content of the input stored as a string.
441
- # @param mime_type [String]
442
- # Optional. The format of the source text, for example, "text/html",
443
- # "text/plain". If left blank, the MIME type defaults to "text/html".
444
- # @param labels [Hash{String => String}]
445
- # Optional. The labels with user-defined metadata for the request.
446
- #
447
- # Label keys and values can be no longer than 63 characters
448
- # (Unicode codepoints), can only contain lowercase letters, numeric
449
- # characters, underscores and dashes. International characters are allowed.
450
- # Label values are optional. Label keys must start with a letter.
451
- #
452
- # See https://cloud.google.com/translate/docs/labels for more information.
453
- # @param options [Google::Gax::CallOptions]
454
- # Overrides the default settings for this call, e.g, timeout,
455
- # retries, etc.
456
- # @yield [result, operation] Access the result along with the RPC operation
457
- # @yieldparam result [Google::Cloud::Translate::V3::DetectLanguageResponse]
458
- # @yieldparam operation [GRPC::ActiveCall::Operation]
459
- # @return [Google::Cloud::Translate::V3::DetectLanguageResponse]
460
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
461
- # @example
462
- # require "google/cloud/translate"
463
- #
464
- # translation_client = Google::Cloud::Translate.new(version: :v3)
465
- # formatted_parent = Google::Cloud::Translate::V3::TranslationServiceClient.location_path("[PROJECT]", "[LOCATION]")
466
- # response = translation_client.detect_language(formatted_parent)
467
-
468
- def detect_language \
469
- parent,
470
- model: nil,
471
- content: nil,
472
- mime_type: nil,
473
- labels: nil,
474
- options: nil,
475
- &block
476
- req = {
477
- parent: parent,
478
- model: model,
479
- content: content,
480
- mime_type: mime_type,
481
- labels: labels
482
- }.delete_if { |_, v| v.nil? }
483
- req = Google::Gax::to_proto(req, Google::Cloud::Translate::V3::DetectLanguageRequest)
484
- @detect_language.call(req, options, &block)
485
- end
486
-
487
- # Returns a list of supported languages for translation.
488
- #
489
- # @param parent [String]
490
- # Required. Project or location to make a call. Must refer to a caller's
491
- # project.
492
- #
493
- # Format: `projects/{project-number-or-id}` or
494
- # `projects/{project-number-or-id}/locations/{location-id}`.
495
- #
496
- # For global calls, use `projects/{project-number-or-id}/locations/global` or
497
- # `projects/{project-number-or-id}`.
498
- #
499
- # Non-global location is required for AutoML models.
500
- #
501
- # Only models within the same region (have same location-id) can be used,
502
- # otherwise an INVALID_ARGUMENT (400) error is returned.
503
- # @param display_language_code [String]
504
- # Optional. The language to use to return localized, human readable names
505
- # of supported languages. If missing, then display names are not returned
506
- # in a response.
507
- # @param model [String]
508
- # Optional. Get supported languages of this model.
509
- #
510
- # The format depends on model type:
511
- #
512
- # * AutoML Translation models:
513
- # `projects/{project-number-or-id}/locations/{location-id}/models/{model-id}`
514
- #
515
- # * General (built-in) models:
516
- # `projects/{project-number-or-id}/locations/{location-id}/models/general/nmt`,
517
- # `projects/{project-number-or-id}/locations/{location-id}/models/general/base`
518
- #
519
- #
520
- # Returns languages supported by the specified model.
521
- # If missing, we get supported languages of Google general base (PBMT) model.
522
- # @param options [Google::Gax::CallOptions]
523
- # Overrides the default settings for this call, e.g, timeout,
524
- # retries, etc.
525
- # @yield [result, operation] Access the result along with the RPC operation
526
- # @yieldparam result [Google::Cloud::Translate::V3::SupportedLanguages]
527
- # @yieldparam operation [GRPC::ActiveCall::Operation]
528
- # @return [Google::Cloud::Translate::V3::SupportedLanguages]
529
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
530
- # @example
531
- # require "google/cloud/translate"
532
- #
533
- # translation_client = Google::Cloud::Translate.new(version: :v3)
534
- # formatted_parent = Google::Cloud::Translate::V3::TranslationServiceClient.location_path("[PROJECT]", "[LOCATION]")
535
- # response = translation_client.get_supported_languages(formatted_parent)
536
-
537
- def get_supported_languages \
538
- parent,
539
- display_language_code: nil,
540
- model: nil,
541
- options: nil,
542
- &block
543
- req = {
544
- parent: parent,
545
- display_language_code: display_language_code,
546
- model: model
547
- }.delete_if { |_, v| v.nil? }
548
- req = Google::Gax::to_proto(req, Google::Cloud::Translate::V3::GetSupportedLanguagesRequest)
549
- @get_supported_languages.call(req, options, &block)
550
- end
551
-
552
- # Translates a large volume of text in asynchronous batch mode.
553
- # This function provides real-time output as the inputs are being processed.
554
- # If caller cancels a request, the partial results (for an input file, it's
555
- # all or nothing) may still be available on the specified output location.
556
- #
557
- # This call returns immediately and you can
558
- # use google.longrunning.Operation.name to poll the status of the call.
559
- #
560
- # @param parent [String]
561
- # Required. Location to make a call. Must refer to a caller's project.
562
- #
563
- # Format: `projects/{project-number-or-id}/locations/{location-id}`.
564
- #
565
- # The `global` location is not supported for batch translation.
566
- #
567
- # Only AutoML Translation models or glossaries within the same region (have
568
- # the same location-id) can be used, otherwise an INVALID_ARGUMENT (400)
569
- # error is returned.
570
- # @param source_language_code [String]
571
- # Required. Source language code.
572
- # @param target_language_codes [Array<String>]
573
- # Required. Specify up to 10 language codes here.
574
- # @param input_configs [Array<Google::Cloud::Translate::V3::InputConfig | Hash>]
575
- # Required. Input configurations.
576
- # The total number of files matched should be <= 1000.
577
- # The total content size should be <= 100M Unicode codepoints.
578
- # The files must use UTF-8 encoding.
579
- # A hash of the same form as `Google::Cloud::Translate::V3::InputConfig`
580
- # can also be provided.
581
- # @param output_config [Google::Cloud::Translate::V3::OutputConfig | Hash]
582
- # Required. Output configuration.
583
- # If 2 input configs match to the same file (that is, same input path),
584
- # we don't generate output for duplicate inputs.
585
- # A hash of the same form as `Google::Cloud::Translate::V3::OutputConfig`
586
- # can also be provided.
587
- # @param models [Hash{String => String}]
588
- # Optional. The models to use for translation. Map's key is target language
589
- # code. Map's value is model name. Value can be a built-in general model,
590
- # or an AutoML Translation model.
591
- #
592
- # The value format depends on model type:
593
- #
594
- # * AutoML Translation models:
595
- # `projects/{project-number-or-id}/locations/{location-id}/models/{model-id}`
596
- #
597
- # * General (built-in) models:
598
- # `projects/{project-number-or-id}/locations/{location-id}/models/general/nmt`,
599
- # `projects/{project-number-or-id}/locations/{location-id}/models/general/base`
600
- #
601
- #
602
- # If the map is empty or a specific model is
603
- # not requested for a language pair, then default google model (nmt) is used.
604
- # @param glossaries [Hash{String => Google::Cloud::Translate::V3::TranslateTextGlossaryConfig | Hash}]
605
- # Optional. Glossaries to be applied for translation.
606
- # It's keyed by target language code.
607
- # A hash of the same form as `Google::Cloud::Translate::V3::TranslateTextGlossaryConfig`
608
- # can also be provided.
609
- # @param labels [Hash{String => String}]
610
- # Optional. The labels with user-defined metadata for the request.
611
- #
612
- # Label keys and values can be no longer than 63 characters
613
- # (Unicode codepoints), can only contain lowercase letters, numeric
614
- # characters, underscores and dashes. International characters are allowed.
615
- # Label values are optional. Label keys must start with a letter.
616
- #
617
- # See https://cloud.google.com/translate/docs/labels for more information.
618
- # @param options [Google::Gax::CallOptions]
619
- # Overrides the default settings for this call, e.g, timeout,
620
- # retries, etc.
621
- # @return [Google::Gax::Operation]
622
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
623
- # @example
624
- # require "google/cloud/translate"
625
- #
626
- # translation_client = Google::Cloud::Translate.new(version: :v3)
627
- # formatted_parent = Google::Cloud::Translate::V3::TranslationServiceClient.location_path("[PROJECT]", "[LOCATION]")
628
- #
629
- # # TODO: Initialize `source_language_code`:
630
- # source_language_code = ''
631
- #
632
- # # TODO: Initialize `target_language_codes`:
633
- # target_language_codes = []
634
- #
635
- # # TODO: Initialize `input_configs`:
636
- # input_configs = []
637
- #
638
- # # TODO: Initialize `output_config`:
639
- # output_config = {}
640
- #
641
- # # Register a callback during the method call.
642
- # operation = translation_client.batch_translate_text(formatted_parent, source_language_code, target_language_codes, input_configs, output_config) do |op|
643
- # raise op.results.message if op.error?
644
- # op_results = op.results
645
- # # Process the results.
646
- #
647
- # metadata = op.metadata
648
- # # Process the metadata.
649
- # end
650
- #
651
- # # Or use the return value to register a callback.
652
- # operation.on_done do |op|
653
- # raise op.results.message if op.error?
654
- # op_results = op.results
655
- # # Process the results.
656
- #
657
- # metadata = op.metadata
658
- # # Process the metadata.
659
- # end
660
- #
661
- # # Manually reload the operation.
662
- # operation.reload!
663
- #
664
- # # Or block until the operation completes, triggering callbacks on
665
- # # completion.
666
- # operation.wait_until_done!
667
-
668
- def batch_translate_text \
669
- parent,
670
- source_language_code,
671
- target_language_codes,
672
- input_configs,
673
- output_config,
674
- models: nil,
675
- glossaries: nil,
676
- labels: nil,
677
- options: nil
678
- req = {
679
- parent: parent,
680
- source_language_code: source_language_code,
681
- target_language_codes: target_language_codes,
682
- input_configs: input_configs,
683
- output_config: output_config,
684
- models: models,
685
- glossaries: glossaries,
686
- labels: labels
687
- }.delete_if { |_, v| v.nil? }
688
- req = Google::Gax::to_proto(req, Google::Cloud::Translate::V3::BatchTranslateTextRequest)
689
- operation = Google::Gax::Operation.new(
690
- @batch_translate_text.call(req, options),
691
- @operations_client,
692
- Google::Cloud::Translate::V3::BatchTranslateResponse,
693
- Google::Cloud::Translate::V3::BatchTranslateMetadata,
694
- call_options: options
695
- )
696
- operation.on_done { |operation| yield(operation) } if block_given?
697
- operation
698
- end
699
-
700
- # Creates a glossary and returns the long-running operation. Returns
701
- # NOT_FOUND, if the project doesn't exist.
702
- #
703
- # @param parent [String]
704
- # Required. The project name.
705
- # @param glossary [Google::Cloud::Translate::V3::Glossary | Hash]
706
- # Required. The glossary to create.
707
- # A hash of the same form as `Google::Cloud::Translate::V3::Glossary`
708
- # can also be provided.
709
- # @param options [Google::Gax::CallOptions]
710
- # Overrides the default settings for this call, e.g, timeout,
711
- # retries, etc.
712
- # @return [Google::Gax::Operation]
713
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
714
- # @example
715
- # require "google/cloud/translate"
716
- #
717
- # translation_client = Google::Cloud::Translate.new(version: :v3)
718
- # formatted_parent = Google::Cloud::Translate::V3::TranslationServiceClient.location_path("[PROJECT]", "[LOCATION]")
719
- #
720
- # # TODO: Initialize `glossary`:
721
- # glossary = {}
722
- #
723
- # # Register a callback during the method call.
724
- # operation = translation_client.create_glossary(formatted_parent, glossary) do |op|
725
- # raise op.results.message if op.error?
726
- # op_results = op.results
727
- # # Process the results.
728
- #
729
- # metadata = op.metadata
730
- # # Process the metadata.
731
- # end
732
- #
733
- # # Or use the return value to register a callback.
734
- # operation.on_done do |op|
735
- # raise op.results.message if op.error?
736
- # op_results = op.results
737
- # # Process the results.
738
- #
739
- # metadata = op.metadata
740
- # # Process the metadata.
741
- # end
742
- #
743
- # # Manually reload the operation.
744
- # operation.reload!
745
- #
746
- # # Or block until the operation completes, triggering callbacks on
747
- # # completion.
748
- # operation.wait_until_done!
749
-
750
- def create_glossary \
751
- parent,
752
- glossary,
753
- options: nil
754
- req = {
755
- parent: parent,
756
- glossary: glossary
757
- }.delete_if { |_, v| v.nil? }
758
- req = Google::Gax::to_proto(req, Google::Cloud::Translate::V3::CreateGlossaryRequest)
759
- operation = Google::Gax::Operation.new(
760
- @create_glossary.call(req, options),
761
- @operations_client,
762
- Google::Cloud::Translate::V3::Glossary,
763
- Google::Cloud::Translate::V3::CreateGlossaryMetadata,
764
- call_options: options
765
- )
766
- operation.on_done { |operation| yield(operation) } if block_given?
767
- operation
768
- end
769
-
770
- # Lists glossaries in a project. Returns NOT_FOUND, if the project doesn't
771
- # exist.
772
- #
773
- # @param parent [String]
774
- # Required. The name of the project from which to list all of the glossaries.
775
- # @param page_size [Integer]
776
- # The maximum number of resources contained in the underlying API
777
- # response. If page streaming is performed per-resource, this
778
- # parameter does not affect the return value. If page streaming is
779
- # performed per-page, this determines the maximum number of
780
- # resources in a page.
781
- # @param filter [String]
782
- # Optional. Filter specifying constraints of a list operation.
783
- # Filtering is not supported yet, and the parameter currently has no effect.
784
- # If missing, no filtering is performed.
785
- # @param options [Google::Gax::CallOptions]
786
- # Overrides the default settings for this call, e.g, timeout,
787
- # retries, etc.
788
- # @yield [result, operation] Access the result along with the RPC operation
789
- # @yieldparam result [Google::Gax::PagedEnumerable<Google::Cloud::Translate::V3::Glossary>]
790
- # @yieldparam operation [GRPC::ActiveCall::Operation]
791
- # @return [Google::Gax::PagedEnumerable<Google::Cloud::Translate::V3::Glossary>]
792
- # An enumerable of Google::Cloud::Translate::V3::Glossary instances.
793
- # See Google::Gax::PagedEnumerable documentation for other
794
- # operations such as per-page iteration or access to the response
795
- # object.
796
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
797
- # @example
798
- # require "google/cloud/translate"
799
- #
800
- # translation_client = Google::Cloud::Translate.new(version: :v3)
801
- # formatted_parent = Google::Cloud::Translate::V3::TranslationServiceClient.location_path("[PROJECT]", "[LOCATION]")
802
- #
803
- # # Iterate over all results.
804
- # translation_client.list_glossaries(formatted_parent).each do |element|
805
- # # Process element.
806
- # end
807
- #
808
- # # Or iterate over results one page at a time.
809
- # translation_client.list_glossaries(formatted_parent).each_page do |page|
810
- # # Process each page at a time.
811
- # page.each do |element|
812
- # # Process element.
813
- # end
814
- # end
815
-
816
- def list_glossaries \
817
- parent,
818
- page_size: nil,
819
- filter: nil,
820
- options: nil,
821
- &block
822
- req = {
823
- parent: parent,
824
- page_size: page_size,
825
- filter: filter
826
- }.delete_if { |_, v| v.nil? }
827
- req = Google::Gax::to_proto(req, Google::Cloud::Translate::V3::ListGlossariesRequest)
828
- @list_glossaries.call(req, options, &block)
829
- end
830
-
831
- # Gets a glossary. Returns NOT_FOUND, if the glossary doesn't
832
- # exist.
833
- #
834
- # @param name [String]
835
- # Required. The name of the glossary to retrieve.
836
- # @param options [Google::Gax::CallOptions]
837
- # Overrides the default settings for this call, e.g, timeout,
838
- # retries, etc.
839
- # @yield [result, operation] Access the result along with the RPC operation
840
- # @yieldparam result [Google::Cloud::Translate::V3::Glossary]
841
- # @yieldparam operation [GRPC::ActiveCall::Operation]
842
- # @return [Google::Cloud::Translate::V3::Glossary]
843
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
844
- # @example
845
- # require "google/cloud/translate"
846
- #
847
- # translation_client = Google::Cloud::Translate.new(version: :v3)
848
- # formatted_name = Google::Cloud::Translate::V3::TranslationServiceClient.glossary_path("[PROJECT]", "[LOCATION]", "[GLOSSARY]")
849
- # response = translation_client.get_glossary(formatted_name)
850
-
851
- def get_glossary \
852
- name,
853
- options: nil,
854
- &block
855
- req = {
856
- name: name
857
- }.delete_if { |_, v| v.nil? }
858
- req = Google::Gax::to_proto(req, Google::Cloud::Translate::V3::GetGlossaryRequest)
859
- @get_glossary.call(req, options, &block)
860
- end
861
-
862
- # Deletes a glossary, or cancels glossary construction
863
- # if the glossary isn't created yet.
864
- # Returns NOT_FOUND, if the glossary doesn't exist.
865
- #
866
- # @param name [String]
867
- # Required. The name of the glossary to delete.
868
- # @param options [Google::Gax::CallOptions]
869
- # Overrides the default settings for this call, e.g, timeout,
870
- # retries, etc.
871
- # @return [Google::Gax::Operation]
872
- # @raise [Google::Gax::GaxError] if the RPC is aborted.
873
- # @example
874
- # require "google/cloud/translate"
875
- #
876
- # translation_client = Google::Cloud::Translate.new(version: :v3)
877
- # formatted_name = Google::Cloud::Translate::V3::TranslationServiceClient.glossary_path("[PROJECT]", "[LOCATION]", "[GLOSSARY]")
878
- #
879
- # # Register a callback during the method call.
880
- # operation = translation_client.delete_glossary(formatted_name) do |op|
881
- # raise op.results.message if op.error?
882
- # op_results = op.results
883
- # # Process the results.
884
- #
885
- # metadata = op.metadata
886
- # # Process the metadata.
887
- # end
888
- #
889
- # # Or use the return value to register a callback.
890
- # operation.on_done do |op|
891
- # raise op.results.message if op.error?
892
- # op_results = op.results
893
- # # Process the results.
894
- #
895
- # metadata = op.metadata
896
- # # Process the metadata.
897
- # end
898
- #
899
- # # Manually reload the operation.
900
- # operation.reload!
901
- #
902
- # # Or block until the operation completes, triggering callbacks on
903
- # # completion.
904
- # operation.wait_until_done!
905
-
906
- def delete_glossary \
907
- name,
908
- options: nil
909
- req = {
910
- name: name
911
- }.delete_if { |_, v| v.nil? }
912
- req = Google::Gax::to_proto(req, Google::Cloud::Translate::V3::DeleteGlossaryRequest)
913
- operation = Google::Gax::Operation.new(
914
- @delete_glossary.call(req, options),
915
- @operations_client,
916
- Google::Cloud::Translate::V3::DeleteGlossaryResponse,
917
- Google::Cloud::Translate::V3::DeleteGlossaryMetadata,
918
- call_options: options
919
- )
920
- operation.on_done { |operation| yield(operation) } if block_given?
921
- operation
922
- end
923
- end
924
- end
925
- end
926
- end
927
- end