google-cloud-translate 0.20.1 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/google-cloud-translate.rb +1 -10
- data/lib/google/cloud/translate.rb +67 -27
- data/lib/google/cloud/translate/api.rb +27 -36
- data/lib/google/cloud/translate/detection.rb +2 -3
- data/lib/google/cloud/translate/language.rb +2 -3
- data/lib/google/cloud/translate/service.rb +1 -1
- data/lib/google/cloud/translate/translation.rb +3 -4
- data/lib/google/cloud/translate/version.rb +1 -1
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00a78c2f05368b2605ee490aa45a5a739c87aa24
|
4
|
+
data.tar.gz: be0de578f2c0307ecff03e49926c419398dc5932
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cdac52bd7be6b4a0aa777b3ae23939ff96f7a2700b8bf67acef6cb42181f15f0cf9e622053380f8b87642d79dc7601ff16bd5c2416e631c54dd675951bfc20d0
|
7
|
+
data.tar.gz: 4a56b6ef0ad05e2fc27ac459fb8b300982f353ee69a52e78c767ff3b5e4a2f48f879c8f18c6587985bd47ee79bc78410457014b5fbd9adba539788280837ebe1
|
@@ -106,16 +106,7 @@ module Google
|
|
106
106
|
#
|
107
107
|
def self.translate key = nil, retries: nil, timeout: nil
|
108
108
|
require "google/cloud/translate"
|
109
|
-
key
|
110
|
-
key ||= ENV["GOOGLE_CLOUD_KEY"]
|
111
|
-
if key.nil?
|
112
|
-
key_missing_msg = "An API key is required to use the Translate API."
|
113
|
-
fail ArgumentError, key_missing_msg
|
114
|
-
end
|
115
|
-
|
116
|
-
Google::Cloud::Translate::Api.new(
|
117
|
-
Google::Cloud::Translate::Service.new(
|
118
|
-
key, retries: retries, timeout: timeout))
|
109
|
+
Google::Cloud::Translate.new key: key, retries: retries, timeout: timeout
|
119
110
|
end
|
120
111
|
end
|
121
112
|
end
|
@@ -53,10 +53,9 @@ module Google
|
|
53
53
|
# language to which you wish to translate.
|
54
54
|
#
|
55
55
|
# ```ruby
|
56
|
-
# require "google/cloud"
|
56
|
+
# require "google/cloud/translate"
|
57
57
|
#
|
58
|
-
#
|
59
|
-
# translate = gcloud.translate
|
58
|
+
# translate = Google::Cloud::Translate.new
|
60
59
|
#
|
61
60
|
# translation = translate.translate "Hello world!", to: "la"
|
62
61
|
#
|
@@ -73,10 +72,9 @@ module Google
|
|
73
72
|
# give Translate API much to work with.)
|
74
73
|
#
|
75
74
|
# ```ruby
|
76
|
-
# require "google/cloud"
|
75
|
+
# require "google/cloud/translate"
|
77
76
|
#
|
78
|
-
#
|
79
|
-
# translate = gcloud.translate
|
77
|
+
# translate = Google::Cloud::Translate.new
|
80
78
|
#
|
81
79
|
# translation = translate.translate "chat", to: "en"
|
82
80
|
#
|
@@ -94,10 +92,9 @@ module Google
|
|
94
92
|
# You can pass multiple texts to {Google::Cloud::Translate::Api#translate}.
|
95
93
|
#
|
96
94
|
# ```ruby
|
97
|
-
# require "google/cloud"
|
95
|
+
# require "google/cloud/translate"
|
98
96
|
#
|
99
|
-
#
|
100
|
-
# translate = gcloud.translate
|
97
|
+
# translate = Google::Cloud::Translate.new
|
101
98
|
#
|
102
99
|
# translations = translate.translate "chien", "chat", from: "fr", to: "en"
|
103
100
|
#
|
@@ -111,10 +108,9 @@ module Google
|
|
111
108
|
# By default, any HTML in your source text will be preserved.
|
112
109
|
#
|
113
110
|
# ```ruby
|
114
|
-
# require "google/cloud"
|
111
|
+
# require "google/cloud/translate"
|
115
112
|
#
|
116
|
-
#
|
117
|
-
# translate = gcloud.translate
|
113
|
+
# translate = Google::Cloud::Translate.new
|
118
114
|
#
|
119
115
|
# translation = translate.translate "<strong>Hello</strong> world!",
|
120
116
|
# to: :la
|
@@ -128,10 +124,9 @@ module Google
|
|
128
124
|
# `confidence` score is a float value between `0` and `1`.
|
129
125
|
#
|
130
126
|
# ```ruby
|
131
|
-
# require "google/cloud"
|
127
|
+
# require "google/cloud/translate"
|
132
128
|
#
|
133
|
-
#
|
134
|
-
# translate = gcloud.translate
|
129
|
+
# translate = Google::Cloud::Translate.new
|
135
130
|
#
|
136
131
|
# detection = translate.detect "chat"
|
137
132
|
#
|
@@ -143,10 +138,9 @@ module Google
|
|
143
138
|
# You can pass multiple texts to {Google::Cloud::Translate::Api#detect}.
|
144
139
|
#
|
145
140
|
# ```ruby
|
146
|
-
# require "google/cloud"
|
141
|
+
# require "google/cloud/translate"
|
147
142
|
#
|
148
|
-
#
|
149
|
-
# translate = gcloud.translate
|
143
|
+
# translate = Google::Cloud::Translate.new
|
150
144
|
#
|
151
145
|
# detections = translate.detect "chien", "chat"
|
152
146
|
#
|
@@ -166,10 +160,9 @@ module Google
|
|
166
160
|
# languages.
|
167
161
|
#
|
168
162
|
# ```ruby
|
169
|
-
# require "google/cloud"
|
163
|
+
# require "google/cloud/translate"
|
170
164
|
#
|
171
|
-
#
|
172
|
-
# translate = gcloud.translate
|
165
|
+
# translate = Google::Cloud::Translate.new
|
173
166
|
#
|
174
167
|
# languages = translate.languages
|
175
168
|
#
|
@@ -183,10 +176,9 @@ module Google
|
|
183
176
|
# provide the code for the language in which you wish to receive the names.
|
184
177
|
#
|
185
178
|
# ```ruby
|
186
|
-
# require "google/cloud"
|
179
|
+
# require "google/cloud/translate"
|
187
180
|
#
|
188
|
-
#
|
189
|
-
# translate = gcloud.translate
|
181
|
+
# translate = Google::Cloud::Translate.new
|
190
182
|
#
|
191
183
|
# languages = translate.languages "en"
|
192
184
|
#
|
@@ -209,13 +201,61 @@ module Google
|
|
209
201
|
# You can also set the request `timeout` value in seconds.
|
210
202
|
#
|
211
203
|
# ```ruby
|
212
|
-
# require "google/cloud"
|
204
|
+
# require "google/cloud/translate"
|
213
205
|
#
|
214
|
-
#
|
215
|
-
# translate = gcloud.translate retries: 10, timeout: 120
|
206
|
+
# translate = Google::Cloud::Translate.new retries: 10, timeout: 120
|
216
207
|
# ```
|
217
208
|
#
|
218
209
|
module Translate
|
210
|
+
##
|
211
|
+
# Creates a new object for connecting to the Translate service.
|
212
|
+
# Each call creates a new connection.
|
213
|
+
#
|
214
|
+
# Unlike other Cloud Platform services, which authenticate using a project
|
215
|
+
# ID and OAuth 2.0 credentials, Google Translate API requires a public API
|
216
|
+
# access key. (This may change in future releases of Google Translate
|
217
|
+
# API.) Follow the general instructions at [Identifying your application
|
218
|
+
# to Google](https://cloud.google.com/translate/v2/using_rest#auth), and
|
219
|
+
# the specific instructions for [Server
|
220
|
+
# keys](https://cloud.google.com/translate/v2/using_rest#creating-server-api-keys).
|
221
|
+
#
|
222
|
+
# @param [String] key a public API access key (not an OAuth 2.0 token)
|
223
|
+
# @param [Integer] retries Number of times to retry requests on server
|
224
|
+
# error. The default value is `3`. Optional.
|
225
|
+
# @param [Integer] timeout Default timeout to use in requests. Optional.
|
226
|
+
#
|
227
|
+
# @return [Google::Cloud::Translate::Api]
|
228
|
+
#
|
229
|
+
# @example
|
230
|
+
# require "google/cloud/translate"
|
231
|
+
#
|
232
|
+
# translate = Google::Cloud::Translate.new key: "api-key-abc123XYZ789"
|
233
|
+
#
|
234
|
+
# translation = translate.translate "Hello world!", to: "la"
|
235
|
+
# translation.text #=> "Salve mundi!"
|
236
|
+
#
|
237
|
+
# @example Using API Key from the environment variable.
|
238
|
+
# require "google/cloud/translate"
|
239
|
+
#
|
240
|
+
# ENV["TRANSLATE_KEY"] = "api-key-abc123XYZ789"
|
241
|
+
#
|
242
|
+
# translate = Google::Cloud::Translate.new
|
243
|
+
#
|
244
|
+
# translation = translate.translate "Hello world!", to: "la"
|
245
|
+
# translation.text #=> "Salve mundi!"
|
246
|
+
#
|
247
|
+
def self.new key: nil, retries: nil, timeout: nil
|
248
|
+
key ||= ENV["TRANSLATE_KEY"]
|
249
|
+
key ||= ENV["GOOGLE_CLOUD_KEY"]
|
250
|
+
if key.nil?
|
251
|
+
key_missing_msg = "An API key is required to use the Translate API."
|
252
|
+
fail ArgumentError, key_missing_msg
|
253
|
+
end
|
254
|
+
|
255
|
+
Google::Cloud::Translate::Api.new(
|
256
|
+
Google::Cloud::Translate::Service.new(
|
257
|
+
key, retries: retries, timeout: timeout))
|
258
|
+
end
|
219
259
|
end
|
220
260
|
end
|
221
261
|
end
|
@@ -36,14 +36,13 @@ module Google
|
|
36
36
|
# Getting Started
|
37
37
|
#
|
38
38
|
# @example
|
39
|
-
# require "google/cloud"
|
39
|
+
# require "google/cloud/translate"
|
40
40
|
#
|
41
|
-
#
|
42
|
-
# translate = gcloud.translate
|
41
|
+
# translate = Google::Cloud::Translate.new
|
43
42
|
#
|
44
43
|
# translation = translate.translate "Hello world!", to: "la"
|
45
44
|
#
|
46
|
-
#
|
45
|
+
# translation.to_s #=> "Salve mundi!"
|
47
46
|
#
|
48
47
|
# translation.from #=> "en"
|
49
48
|
# translation.origin #=> "Hello world!"
|
@@ -89,14 +88,13 @@ module Google
|
|
89
88
|
# objects if multiple texts were given.
|
90
89
|
#
|
91
90
|
# @example
|
92
|
-
# require "google/cloud"
|
91
|
+
# require "google/cloud/translate"
|
93
92
|
#
|
94
|
-
#
|
95
|
-
# translate = gcloud.translate
|
93
|
+
# translate = Google::Cloud::Translate.new
|
96
94
|
#
|
97
95
|
# translation = translate.translate "Hello world!", to: "la"
|
98
96
|
#
|
99
|
-
#
|
97
|
+
# translation.to_s #=> "Salve mundi!"
|
100
98
|
#
|
101
99
|
# translation.detected? #=> true
|
102
100
|
# translation.from #=> "en"
|
@@ -105,10 +103,9 @@ module Google
|
|
105
103
|
# translation.text #=> "Salve mundi!"
|
106
104
|
#
|
107
105
|
# @example Setting the `from` language.
|
108
|
-
# require "google/cloud"
|
106
|
+
# require "google/cloud/translate"
|
109
107
|
#
|
110
|
-
#
|
111
|
-
# translate = gcloud.translate
|
108
|
+
# translate = Google::Cloud::Translate.new
|
112
109
|
#
|
113
110
|
# translation = translate.translate "Hello world!",
|
114
111
|
# from: :en, to: :la
|
@@ -116,10 +113,9 @@ module Google
|
|
116
113
|
# translation.text #=> "Salve mundi!"
|
117
114
|
#
|
118
115
|
# @example Retrieving multiple translations.
|
119
|
-
# require "google/cloud"
|
116
|
+
# require "google/cloud/translate"
|
120
117
|
#
|
121
|
-
#
|
122
|
-
# translate = gcloud.translate
|
118
|
+
# translate = Google::Cloud::Translate.new
|
123
119
|
#
|
124
120
|
# translations = translate.translate "Hello my friend.",
|
125
121
|
# "See you soon.",
|
@@ -129,10 +125,9 @@ module Google
|
|
129
125
|
# translations[1].text #=> "Vide te mox."
|
130
126
|
#
|
131
127
|
# @example Preserving HTML tags.
|
132
|
-
# require "google/cloud"
|
128
|
+
# require "google/cloud/translate"
|
133
129
|
#
|
134
|
-
#
|
135
|
-
# translate = gcloud.translate
|
130
|
+
# translate = Google::Cloud::Translate.new
|
136
131
|
#
|
137
132
|
# translation = translate.translate "<strong>Hello</strong> world!",
|
138
133
|
# to: :la
|
@@ -165,28 +160,26 @@ module Google
|
|
165
160
|
# multiple texts were given.
|
166
161
|
#
|
167
162
|
# @example
|
168
|
-
# require "google/cloud"
|
163
|
+
# require "google/cloud/translate"
|
169
164
|
#
|
170
|
-
#
|
171
|
-
# translate = gcloud.translate
|
165
|
+
# translate = Google::Cloud::Translate.new
|
172
166
|
#
|
173
167
|
# detection = translate.detect "Hello world!"
|
174
|
-
#
|
175
|
-
#
|
168
|
+
# detection.language #=> "en"
|
169
|
+
# detection.confidence #=> 0.7100697
|
176
170
|
#
|
177
171
|
# @example Detecting multiple texts.
|
178
|
-
# require "google/cloud"
|
172
|
+
# require "google/cloud/translate"
|
179
173
|
#
|
180
|
-
#
|
181
|
-
# translate = gcloud.translate
|
174
|
+
# translate = Google::Cloud::Translate.new
|
182
175
|
#
|
183
176
|
# detections = translate.detect "Hello world!",
|
184
177
|
# "Bonjour le monde!"
|
185
|
-
#
|
186
|
-
#
|
187
|
-
#
|
188
|
-
#
|
189
|
-
#
|
178
|
+
# detections.count #=> 2
|
179
|
+
# detections.first.language #=> "en"
|
180
|
+
# detections.first.confidence #=> 0.7100697
|
181
|
+
# detections.last.language #=> "fr"
|
182
|
+
# detections.last.confidence #=> 0.40440267
|
190
183
|
#
|
191
184
|
def detect *text
|
192
185
|
return nil if text.empty?
|
@@ -210,10 +203,9 @@ module Google
|
|
210
203
|
# the API.
|
211
204
|
#
|
212
205
|
# @example
|
213
|
-
# require "google/cloud"
|
206
|
+
# require "google/cloud/translate"
|
214
207
|
#
|
215
|
-
#
|
216
|
-
# translate = gcloud.translate
|
208
|
+
# translate = Google::Cloud::Translate.new
|
217
209
|
#
|
218
210
|
# languages = translate.languages
|
219
211
|
# languages.count #=> 104
|
@@ -222,10 +214,9 @@ module Google
|
|
222
214
|
# english.name #=> nil
|
223
215
|
#
|
224
216
|
# @example Get all languages with their names in French.
|
225
|
-
# require "google/cloud"
|
217
|
+
# require "google/cloud/translate"
|
226
218
|
#
|
227
|
-
#
|
228
|
-
# translate = gcloud.translate
|
219
|
+
# translate = Google::Cloud::Translate.new
|
229
220
|
#
|
230
221
|
# languages = translate.languages "fr"
|
231
222
|
# languages.count #=> 104
|
@@ -26,10 +26,9 @@ module Google
|
|
26
26
|
# Detect Language
|
27
27
|
#
|
28
28
|
# @example
|
29
|
-
# require "google/cloud"
|
29
|
+
# require "google/cloud/translate"
|
30
30
|
#
|
31
|
-
#
|
32
|
-
# translate = gcloud.translate
|
31
|
+
# translate = Google::Cloud::Translate.new
|
33
32
|
#
|
34
33
|
# detections = translate.detect "chien", "chat"
|
35
34
|
#
|
@@ -26,10 +26,9 @@ module Google
|
|
26
26
|
# Discover Supported Languages
|
27
27
|
#
|
28
28
|
# @example
|
29
|
-
# require "google/cloud"
|
29
|
+
# require "google/cloud/translate"
|
30
30
|
#
|
31
|
-
#
|
32
|
-
# translate = gcloud.translate
|
31
|
+
# translate = Google::Cloud::Translate.new
|
33
32
|
#
|
34
33
|
# languages = translate.languages "en"
|
35
34
|
#
|
@@ -34,7 +34,7 @@ module Google
|
|
34
34
|
# Creates a new Service instance.
|
35
35
|
def initialize key, retries: nil, timeout: nil
|
36
36
|
@service = API::TranslateService.new
|
37
|
-
@service.client_options.application_name = "
|
37
|
+
@service.client_options.application_name = "gcloud-ruby"
|
38
38
|
@service.client_options.application_version = \
|
39
39
|
Google::Cloud::Translate::VERSION
|
40
40
|
@service.request_options.retries = retries || 3
|
@@ -26,14 +26,13 @@ module Google
|
|
26
26
|
# Translate Text
|
27
27
|
#
|
28
28
|
# @example
|
29
|
-
# require "google/cloud"
|
29
|
+
# require "google/cloud/translate"
|
30
30
|
#
|
31
|
-
#
|
32
|
-
# translate = gcloud.translate
|
31
|
+
# translate = Google::Cloud::Translate.new
|
33
32
|
#
|
34
33
|
# translation = translate.translate "Hello world!", to: "la"
|
35
34
|
#
|
36
|
-
#
|
35
|
+
# translation.to_s #=> "Salve mundi!"
|
37
36
|
#
|
38
37
|
# translation.from #=> "en"
|
39
38
|
# translation.origin #=> "Hello world!"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-cloud-translate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.21.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Moore
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-10-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: google-cloud-core
|
@@ -17,14 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: 0.
|
20
|
+
version: 0.21.0
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: 0.
|
27
|
+
version: 0.21.0
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: google-api-client
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -151,6 +151,20 @@ dependencies:
|
|
151
151
|
- - "~>"
|
152
152
|
- !ruby/object:Gem::Version
|
153
153
|
version: '0.9'
|
154
|
+
- !ruby/object:Gem::Dependency
|
155
|
+
name: yard-doctest
|
156
|
+
requirement: !ruby/object:Gem::Requirement
|
157
|
+
requirements:
|
158
|
+
- - "~>"
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: 0.1.6
|
161
|
+
type: :development
|
162
|
+
prerelease: false
|
163
|
+
version_requirements: !ruby/object:Gem::Requirement
|
164
|
+
requirements:
|
165
|
+
- - "~>"
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
version: 0.1.6
|
154
168
|
description: google-cloud-translate is the official library for Google Translate API.
|
155
169
|
email:
|
156
170
|
- mike@blowmage.com
|