google-cloud-translate 1.2.2 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 20aedb79118d5f0746a0518fd9d62a707a0ee58f3538c4d8e50fe5868a92ca7c
4
- data.tar.gz: 2df9d69ede2de2f7f0a6b206c44ca8d31849b91763af7c94283cd84723909488
3
+ metadata.gz: 66bb2ba4eeacb8570dcba4a34e0fb25e1214c02de23b34619adf0b3eb3886531
4
+ data.tar.gz: d0aeeca2098dfe17392b35b52e36a32a0ba5a815b770ccc3cf137953d2938e22
5
5
  SHA512:
6
- metadata.gz: 2a5e0b020842c1e96dcd033c06c12e69e42b1f6c9fe894f31664fe3664683f5deaef4172239915f650bdf237c91167f3687d74d7c5991dc91b12edec53db3f69
7
- data.tar.gz: af719e821badb9d811591774f41d62d84429e398592f8c6728d15102c33d76c84340d80e6f8ef5c3500382b18307835a41b61dcc0f4da95a08159df0209f093e
6
+ metadata.gz: ebf31921e3d2adfa5cc04ff9a8bd4520606919d19aefc8dcef55484b2b681899df76e8b89ab343508c1559cab780c68b6179220bb6f920cedfcdb5e8bc46486c
7
+ data.tar.gz: 06ca413c3e1053029c5ce2445726127c20be331549a774535703a99eb9b78ef586d0f6400e0881c851d42658c235c17738f15b098718b8da48d7e512581763a0
data/AUTHENTICATION.md ADDED
@@ -0,0 +1,179 @@
1
+ # Authentication
2
+
3
+ In general, the google-cloud-translate library uses [Service
4
+ Account](https://cloud.google.com/iam/docs/creating-managing-service-accounts)
5
+ credentials to connect to Google Cloud services. When running on Compute Engine
6
+ the credentials will be discovered automatically. When running on other
7
+ environments, the Service Account credentials can be specified by providing the
8
+ path to the [JSON
9
+ keyfile](https://cloud.google.com/iam/docs/managing-service-account-keys) for
10
+ the account (or the JSON itself) in environment variables. Additionally, Cloud
11
+ SDK credentials can also be discovered automatically, but this is only
12
+ recommended during development.
13
+
14
+ ## Project and Credential Lookup
15
+
16
+ The google-cloud-translate library aims to make authentication as simple as
17
+ possible, and provides several mechanisms to configure your system without
18
+ providing **Project ID** and **Service Account Credentials** directly in code.
19
+
20
+ **Project ID** is discovered in the following order:
21
+
22
+ 1. Specify project ID in method arguments
23
+ 2. Specify project ID in configuration
24
+ 3. Discover project ID in environment variables
25
+ 4. Discover GCE project ID
26
+
27
+ **Credentials** are discovered in the following order:
28
+
29
+ 1. Specify credentials in method arguments
30
+ 2. Specify credentials in configuration
31
+ 3. Discover credentials path in environment variables
32
+ 4. Discover credentials JSON in environment variables
33
+ 5. Discover credentials file in the Cloud SDK's path
34
+ 6. Discover GCE credentials
35
+
36
+ ### Google Cloud Platform environments
37
+
38
+ While running on Google Cloud Platform environments such as Google Compute
39
+ Engine, Google App Engine and Google Kubernetes Engine, no extra work is needed.
40
+ The **Project ID** and **Credentials** and are discovered automatically. Code
41
+ should be written as if already authenticated. Just be sure when you [set up the
42
+ GCE instance][gce-how-to], you add the correct scopes for the APIs you want to
43
+ access. For example:
44
+
45
+ * **All APIs**
46
+ * `https://www.googleapis.com/auth/cloud-platform`
47
+ * `https://www.googleapis.com/auth/cloud-platform.read-only`
48
+ * **BigQuery**
49
+ * `https://www.googleapis.com/auth/bigquery`
50
+ * `https://www.googleapis.com/auth/bigquery.insertdata`
51
+ * **Compute Engine**
52
+ * `https://www.googleapis.com/auth/compute`
53
+ * **Datastore**
54
+ * `https://www.googleapis.com/auth/datastore`
55
+ * `https://www.googleapis.com/auth/userinfo.email`
56
+ * **DNS**
57
+ * `https://www.googleapis.com/auth/ndev.clouddns.readwrite`
58
+ * **Pub/Sub**
59
+ * `https://www.googleapis.com/auth/pubsub`
60
+ * **Storage**
61
+ * `https://www.googleapis.com/auth/devstorage.full_control`
62
+ * `https://www.googleapis.com/auth/devstorage.read_only`
63
+ * `https://www.googleapis.com/auth/devstorage.read_write`
64
+
65
+ ### Environment Variables
66
+
67
+ The **Project ID** and **Credentials JSON** can be placed in environment
68
+ variables instead of declaring them directly in code. Each service has its own
69
+ environment variable, allowing for different service accounts to be used for
70
+ different services. (See the READMEs for the individual service gems for
71
+ details.) The path to the **Credentials JSON** file can be stored in the
72
+ environment variable, or the **Credentials JSON** itself can be stored for
73
+ environments such as Docker containers where writing files is difficult or not
74
+ encouraged.
75
+
76
+ The environment variables that Translation checks for project ID are:
77
+
78
+ 1. `TRANSLATE_PROJECT`
79
+ 2. `GOOGLE_CLOUD_PROJECT`
80
+
81
+ The environment variables that Translation checks for credentials are configured
82
+ on {Google::Cloud::Translate::Credentials}:
83
+
84
+ 1. `TRANSLATE_CREDENTIALS` - Path to JSON file, or JSON contents
85
+ 2. `TRANSLATE_KEYFILE` - Path to JSON file, or JSON contents
86
+ 3. `GOOGLE_CLOUD_CREDENTIALS` - Path to JSON file, or JSON contents
87
+ 4. `GOOGLE_CLOUD_KEYFILE` - Path to JSON file, or JSON contents
88
+ 5. `GOOGLE_APPLICATION_CREDENTIALS` - Path to JSON file
89
+
90
+ ```ruby
91
+ require "google/cloud/translate"
92
+
93
+ ENV["TRANSLATE_PROJECT"] = "my-project-id"
94
+ ENV["TRANSLATE_CREDENTIALS"] = "path/to/keyfile.json"
95
+
96
+ translate = Google::Cloud::Translate.new
97
+ ```
98
+
99
+ ### Configuration
100
+
101
+ The **Project ID** and **Credentials JSON** can be configured instead of placing them in environment variables or providing them as arguments.
102
+
103
+ ```ruby
104
+ require "google/cloud/translate"
105
+
106
+ Google::Cloud::Translate.configure do |config|
107
+ config.project_id = "my-project-id"
108
+ config.credentials = "path/to/keyfile.json"
109
+ end
110
+
111
+ translate = Google::Cloud::Translate.new
112
+ ```
113
+
114
+ ### Cloud SDK
115
+
116
+ This option allows for an easy way to authenticate during development. If
117
+ credentials are not provided in code or in environment variables, then Cloud SDK
118
+ credentials are discovered.
119
+
120
+ To configure your system for this, simply:
121
+
122
+ 1. [Download and install the Cloud SDK](https://cloud.google.com/sdk)
123
+ 2. Authenticate using OAuth 2.0 `$ gcloud auth login`
124
+ 3. Write code as if already authenticated.
125
+
126
+ **NOTE:** This is _not_ recommended for running in production. The Cloud SDK
127
+ *should* only be used during development.
128
+
129
+ [gce-how-to]: https://cloud.google.com/compute/docs/authentication#using
130
+ [dev-console]: https://console.cloud.google.com/project
131
+
132
+ [enable-apis]: https://raw.githubusercontent.com/GoogleCloudPlatform/gcloud-common/master/authentication/enable-apis.png
133
+
134
+ [create-new-service-account]: https://raw.githubusercontent.com/GoogleCloudPlatform/gcloud-common/master/authentication/create-new-service-account.png
135
+ [create-new-service-account-existing-keys]: https://raw.githubusercontent.com/GoogleCloudPlatform/gcloud-common/master/authentication/create-new-service-account-existing-keys.png
136
+ [reuse-service-account]: https://raw.githubusercontent.com/GoogleCloudPlatform/gcloud-common/master/authentication/reuse-service-account.png
137
+
138
+ ## Creating a Service Account
139
+
140
+ Google Cloud requires a **Project ID** and **Service Account Credentials** to
141
+ connect to the APIs. You will use the **Project ID** and **JSON key file** to
142
+ connect to most services with google-cloud-translate.
143
+
144
+ If you are not running this client on Google Compute Engine, you need a Google
145
+ Developers service account.
146
+
147
+ 1. Visit the [Google Developers Console][dev-console].
148
+ 1. Create a new project or click on an existing project.
149
+ 1. Activate the slide-out navigation tray and select **API Manager**. From
150
+ here, you will enable the APIs that your application requires.
151
+
152
+ ![Enable the APIs that your application requires][enable-apis]
153
+
154
+ *Note: You may need to enable billing in order to use these services.*
155
+
156
+ 1. Select **Credentials** from the side navigation.
157
+
158
+ You should see a screen like one of the following.
159
+
160
+ ![Create a new service account][create-new-service-account]
161
+
162
+ ![Create a new service account With Existing Keys][create-new-service-account-existing-keys]
163
+
164
+ Find the "Add credentials" drop down and select "Service account" to be
165
+ guided through downloading a new JSON key file.
166
+
167
+ If you want to re-use an existing service account, you can easily generate a
168
+ new key file. Just select the account you wish to re-use, and click "Generate
169
+ new JSON key":
170
+
171
+ ![Re-use an existing service account][reuse-service-account]
172
+
173
+ The key file you download will be used by this library to authenticate API
174
+ requests and should be stored in a secure location.
175
+
176
+ ## Troubleshooting
177
+
178
+ If you're having trouble authenticating you can ask for help by following the
179
+ {file:TROUBLESHOOTING.md Troubleshooting Guide}.
data/CHANGELOG.md ADDED
@@ -0,0 +1,70 @@
1
+ # Release History
2
+
3
+ ### 1.2.3 / 2018-09-12
4
+
5
+ * Add missing documentation files to package.
6
+
7
+ ### 1.2.2 / 2018-09-10
8
+
9
+ * Update documentation.
10
+
11
+ ### 1.2.1 / 2018-08-21
12
+
13
+ * Update documentation.
14
+
15
+ ### 1.2.0 / 2018-02-27
16
+
17
+ * Support Shared Configuration.
18
+
19
+ ### 1.1.0 / 2017-11-14
20
+
21
+ * Add `Google::Cloud::Translate::Credentials` class.
22
+ * Rename constructor arguments to `project_id` and `credentials`.
23
+ (The previous arguments `project` and `keyfile` are still supported.)
24
+ * Document `Google::Auth::Credentials` as `credentials` value.
25
+ * Updated `faraday`, `googleauth` dependencies.
26
+
27
+ ### 1.0.1 / 2017-07-11
28
+
29
+ * Remove mention of discontinued Premium Edition billing from documentation.
30
+
31
+ ### 1.0.0 / 2017-06-28
32
+
33
+ * Release 1.0
34
+
35
+ ### 0.23.1 / 2017-05-23
36
+
37
+ * Fix error handling (adrian-gomez)
38
+
39
+ ### 0.23.0 / 2017-03-31
40
+
41
+ * No changes
42
+
43
+ ### 0.22.2 / 2016-12-22
44
+
45
+ * Change product name to Google Cloud Translation API in docs.
46
+
47
+ ### 0.22.1 / 2016-11-16
48
+
49
+ * Add missing googleauth dependency (frankyn)
50
+
51
+ ### 0.22.0 / 2016-11-14
52
+
53
+ * Support authentication with service accounts
54
+ * Add `model` parameter to translate method
55
+ * Add `model` attribute to Translation objects
56
+
57
+ ### 0.21.0 / 2016-10-20
58
+
59
+ * New service constructor Google::Cloud::Translate.new
60
+
61
+ ### 0.20.1 / 2016-09-02
62
+
63
+ * Fix for timeout on uploads.
64
+
65
+ ### 0.20.0 / 2016-08-26
66
+
67
+ This gem contains the Google Cloud Translate service implementation for the `google-cloud` gem. The `google-cloud` gem replaces the old `gcloud` gem. Legacy code can continue to use the `gcloud` gem.
68
+
69
+ * Namespace is now `Google::Cloud`
70
+ * The `google-cloud` gem is now an umbrella package for individual gems
@@ -0,0 +1,40 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct.
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or reject
24
+ comments, commits, code, wiki edits, issues, and other contributions that are
25
+ not aligned to this Code of Conduct. By adopting this Code of Conduct, project
26
+ maintainers commit themselves to fairly and consistently applying these
27
+ principles to every aspect of managing this project. Project maintainers who do
28
+ not follow or enforce the Code of Conduct may be permanently removed from the
29
+ project team.
30
+
31
+ This code of conduct applies both within project spaces and in public spaces
32
+ when an individual is representing the project or its community.
33
+
34
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
35
+ reported by opening an issue or contacting one or more of the project
36
+ maintainers.
37
+
38
+ This Code of Conduct is adapted from the [Contributor
39
+ Covenant](http://contributor-covenant.org), version 1.2.0, available at
40
+ [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/)
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,188 @@
1
+ # Contributing to Google Cloud Translation
2
+
3
+ 1. **Sign one of the contributor license agreements below.**
4
+ 2. Fork the repo, develop and test your code changes.
5
+ 3. Send a pull request.
6
+
7
+ ## Contributor License Agreements
8
+
9
+ Before we can accept your pull requests you'll need to sign a Contributor
10
+ License Agreement (CLA):
11
+
12
+ - **If you are an individual writing original source code** and **you own the
13
+ intellectual property**, then you'll need to sign an [individual
14
+ CLA](https://developers.google.com/open-source/cla/individual).
15
+ - **If you work for a company that wants to allow you to contribute your work**,
16
+ then you'll need to sign a [corporate
17
+ CLA](https://developers.google.com/open-source/cla/corporate).
18
+
19
+ You can sign these electronically (just scroll to the bottom). After that, we'll
20
+ be able to accept your pull requests.
21
+
22
+ ## Setup
23
+
24
+ In order to use the google-cloud-translate console and run the project's tests,
25
+ there is a small amount of setup:
26
+
27
+ 1. Install Ruby. google-cloud-translate requires Ruby 2.3+. You may choose to
28
+ manage your Ruby and gem installations with [RVM](https://rvm.io/),
29
+ [rbenv](https://github.com/rbenv/rbenv), or
30
+ [chruby](https://github.com/postmodern/chruby).
31
+
32
+ 2. Install [Bundler](http://bundler.io/).
33
+
34
+ ```sh
35
+ $ gem install bundler
36
+ ```
37
+
38
+ 3. Install the top-level project dependencies.
39
+
40
+ ```sh
41
+ $ bundle install
42
+ ```
43
+
44
+ 4. Install the Translation dependencies.
45
+
46
+ ```sh
47
+ $ cd google-cloud-translate/
48
+ $ bundle exec rake bundleupdate
49
+ ```
50
+
51
+ ## Console
52
+
53
+ In order to run code interactively, you can automatically load
54
+ google-cloud-translate and its dependencies in IRB. This requires that your
55
+ developer environment has already been configured by following the steps
56
+ described in the {file:AUTHENTICATION.md Authentication Guide}. An IRB console
57
+ can be created with:
58
+
59
+ ```sh
60
+ $ cd google-cloud-translate/
61
+ $ bundle exec rake console
62
+ ```
63
+
64
+ ## Translation Tests
65
+
66
+ Tests are very important part of google-cloud-translate. All contributions
67
+ should include tests that ensure the contributed code behaves as expected.
68
+
69
+ To run the unit tests, documentation tests, and code style checks together for a
70
+ package:
71
+
72
+ ``` sh
73
+ $ cd google-cloud-translate/
74
+ $ bundle exec rake ci
75
+ ```
76
+
77
+ To run the command above, plus all acceptance tests, use `rake ci:acceptance` or
78
+ its handy alias, `rake ci:a`.
79
+
80
+ ### Translation Unit Tests
81
+
82
+
83
+ The project uses the [minitest](https://github.com/seattlerb/minitest) library,
84
+ including [specs](https://github.com/seattlerb/minitest#specs),
85
+ [mocks](https://github.com/seattlerb/minitest#mocks) and
86
+ [minitest-autotest](https://github.com/seattlerb/minitest-autotest).
87
+
88
+ To run the Translation unit tests:
89
+
90
+ ``` sh
91
+ $ cd google-cloud-translate/
92
+ $ bundle exec rake test
93
+ ```
94
+
95
+ ### Translation Documentation Tests
96
+
97
+ The project tests the code examples in the gem's
98
+ [YARD](https://github.com/lsegal/yard)-based documentation.
99
+
100
+ The example testing functions in a way that is very similar to unit testing, and
101
+ in fact the library providing it,
102
+ [yard-doctest](https://github.com/p0deje/yard-doctest), is based on the
103
+ project's unit test library, [minitest](https://github.com/seattlerb/minitest).
104
+
105
+ To run the Translation documentation tests:
106
+
107
+ ``` sh
108
+ $ cd google-cloud-translate/
109
+ $ bundle exec rake doctest
110
+ ```
111
+
112
+ If you add, remove or modify documentation examples when working on a pull
113
+ request, you may need to update the setup for the tests. The stubs and mocks
114
+ required to run the tests are located in `support/doctest_helper.rb`. Please
115
+ note that much of the setup is matched by the title of the
116
+ [`@example`](http://www.rubydoc.info/gems/yard/file/docs/Tags.md#example) tag.
117
+ If you alter an example's title, you may encounter breaking tests.
118
+
119
+ ### Translation Acceptance Tests
120
+
121
+ The Translation acceptance tests interact with the live service API. Follow the
122
+ instructions in the {file:AUTHENTICATION.md Authentication guide} for enabling
123
+ the Translation API. Occasionally, some API features may not yet be generally
124
+ available, making it difficult for some contributors to successfully run the
125
+ entire acceptance test suite. However, please ensure that you do successfully
126
+ run acceptance tests for any code areas covered by your pull request.
127
+
128
+ To run the acceptance tests, first create and configure a project in the Google
129
+ Developers Console, as described in the {file:AUTHENTICATION.md Authentication
130
+ guide}. Be sure to download the JSON KEY file. Make note of the PROJECT_ID and
131
+ the KEYFILE location on your system.
132
+
133
+ Before you can run the Translation acceptance tests, you must first create indexes
134
+ used in the tests.
135
+
136
+ #### Running the Translation acceptance tests
137
+
138
+ To run the Translation acceptance tests:
139
+
140
+ ``` sh
141
+ $ cd google-cloud-translate/
142
+ $ bundle exec rake acceptance[\\{my-project-id},\\{/path/to/keyfile.json}]
143
+ ```
144
+
145
+ Or, if you prefer you can store the values in the `GCLOUD_TEST_PROJECT` and
146
+ `GCLOUD_TEST_KEYFILE` environment variables:
147
+
148
+ ``` sh
149
+ $ cd google-cloud-translate/
150
+ $ export GCLOUD_TEST_PROJECT=\\{my-project-id}
151
+ $ export GCLOUD_TEST_KEYFILE=\\{/path/to/keyfile.json}
152
+ $ bundle exec rake acceptance
153
+ ```
154
+
155
+ If you want to use a different project and credentials for acceptance tests, you
156
+ can use the more specific `TRANSLATE_TEST_PROJECT` and `TRANSLATE_TEST_KEYFILE`
157
+ environment variables:
158
+
159
+ ``` sh
160
+ $ cd google-cloud-translate/
161
+ $ export TRANSLATE_TEST_PROJECT=\\{my-project-id}
162
+ $ export TRANSLATE_TEST_KEYFILE=\\{/path/to/keyfile.json}
163
+ $ bundle exec rake acceptance
164
+ ```
165
+
166
+ ## Coding Style
167
+
168
+ Please follow the established coding style in the library. The style is is
169
+ largely based on [The Ruby Style
170
+ Guide](https://github.com/bbatsov/ruby-style-guide) with a few exceptions based
171
+ on seattle-style:
172
+
173
+ * Avoid parenthesis when possible, including in method definitions.
174
+ * Always use double quotes strings. ([Option
175
+ B](https://github.com/bbatsov/ruby-style-guide#strings))
176
+
177
+ You can check your code against these rules by running Rubocop like so:
178
+
179
+ ```sh
180
+ $ cd google-cloud-translate/
181
+ $ bundle exec rake rubocop
182
+ ```
183
+
184
+ ## Code of Conduct
185
+
186
+ Please note that this project is released with a Contributor Code of Conduct. By
187
+ participating in this project you agree to abide by its terms. See
188
+ {file:CODE_OF_CONDUCT.md Code of Conduct} for more information.
data/OVERVIEW.md ADDED
@@ -0,0 +1,185 @@
1
+ # Google Cloud Translation API
2
+
3
+ [Google Cloud Translation API](https://cloud.google.com/translation/)
4
+ provides a simple, programmatic interface for translating an arbitrary
5
+ string into any supported language. It is highly responsive, so websites
6
+ and applications can integrate with Translation API for fast, dynamic
7
+ translation of source text. Language detection is also available in cases
8
+ where the source language is unknown.
9
+
10
+ Translation API supports more than one hundred different languages, from
11
+ Afrikaans to Zulu. Used in combination, this enables translation between
12
+ thousands of language pairs. Also, you can send in HTML and receive HTML
13
+ with translated text back. You don't need to extract your source text or
14
+ reassemble the translated content.
15
+
16
+ ## Authenticating
17
+
18
+ Like other Cloud Platform services, Google Cloud Translation API supports
19
+ authentication using a project ID and OAuth 2.0 credentials. In addition,
20
+ it supports authentication using a public API access key. (If both the API
21
+ key and the project and OAuth 2.0 credentials are provided, the API key
22
+ will be used.) Instructions and configuration options are covered in the
23
+ {file:AUTHENTICATION.md Authentication Guide}.
24
+
25
+ ## Translating texts
26
+
27
+ Translating text from one language to another is easy (and extremely
28
+ fast.) The only required arguments to
29
+ {Google::Cloud::Translate::Api#translate} are a string and the [ISO
30
+ 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) code of the
31
+ language to which you wish to translate.
32
+
33
+ ```ruby
34
+ require "google/cloud/translate"
35
+
36
+ translate = Google::Cloud::Translate.new
37
+
38
+ translation = translate.translate "Hello world!", to: "la"
39
+
40
+ puts translation #=> Salve mundi!
41
+
42
+ translation.from #=> "en"
43
+ translation.origin #=> "Hello world!"
44
+ translation.to #=> "la"
45
+ translation.text #=> "Salve mundi!"
46
+ ```
47
+
48
+ You may want to use the `from` option to specify the language of the
49
+ source text, as the following example illustrates. (Single words do not
50
+ give Translation API much to work with.)
51
+
52
+ ```ruby
53
+ require "google/cloud/translate"
54
+
55
+ translate = Google::Cloud::Translate.new
56
+
57
+ translation = translate.translate "chat", to: "en"
58
+
59
+ translation.detected? #=> true
60
+ translation.from #=> "en"
61
+ translation.text #=> "chat"
62
+
63
+ translation = translate.translate "chat", from: "fr", to: "en"
64
+
65
+ translation.detected? #=> false
66
+ translation.from #=> "fr"
67
+ translation.text #=> "cat"
68
+ ```
69
+
70
+ You can pass multiple texts to {Google::Cloud::Translate::Api#translate}.
71
+
72
+ ```ruby
73
+ require "google/cloud/translate"
74
+
75
+ translate = Google::Cloud::Translate.new
76
+
77
+ translations = translate.translate "chien", "chat", from: "fr", to: "en"
78
+
79
+ translations.size #=> 2
80
+ translations[0].origin #=> "chien"
81
+ translations[0].text #=> "dog"
82
+ translations[1].origin #=> "chat"
83
+ translations[1].text #=> "cat"
84
+ ```
85
+
86
+ By default, any HTML in your source text will be preserved.
87
+
88
+ ```ruby
89
+ require "google/cloud/translate"
90
+
91
+ translate = Google::Cloud::Translate.new
92
+
93
+ translation = translate.translate "<strong>Hello</strong> world!",
94
+ to: :la
95
+ translation.text #=> "<strong>Salve</strong> mundi!"
96
+ ```
97
+
98
+ ## Detecting languages
99
+
100
+ You can use {Google::Cloud::Translate::Api#detect} to see which language
101
+ the Translation API ranks as the most likely source language for a text.
102
+ The `confidence` score is a float value between `0` and `1`.
103
+
104
+ ```ruby
105
+ require "google/cloud/translate"
106
+
107
+ translate = Google::Cloud::Translate.new
108
+
109
+ detection = translate.detect "chat"
110
+
111
+ detection.text #=> "chat"
112
+ detection.language #=> "en"
113
+ detection.confidence #=> 0.59922177
114
+ ```
115
+
116
+ You can pass multiple texts to {Google::Cloud::Translate::Api#detect}.
117
+
118
+ ```ruby
119
+ require "google/cloud/translate"
120
+
121
+ translate = Google::Cloud::Translate.new
122
+
123
+ detections = translate.detect "chien", "chat"
124
+
125
+ detections.size #=> 2
126
+ detections[0].text #=> "chien"
127
+ detections[0].language #=> "fr"
128
+ detections[0].confidence #=> 0.7109375
129
+ detections[1].text #=> "chat"
130
+ detections[1].language #=> "en"
131
+ detections[1].confidence #=> 0.59922177
132
+ ```
133
+
134
+ ## Listing supported languages
135
+
136
+ Translation API adds new languages frequently. You can use
137
+ {Google::Cloud::Translate::Api#languages} to query the list of supported
138
+ languages.
139
+
140
+ ```ruby
141
+ require "google/cloud/translate"
142
+
143
+ translate = Google::Cloud::Translate.new
144
+
145
+ languages = translate.languages
146
+
147
+ languages.size #=> 104
148
+ languages[0].code #=> "af"
149
+ languages[0].name #=> nil
150
+ ```
151
+
152
+ To receive the names of the supported languages, as well as their [ISO
153
+ 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) codes,
154
+ provide the code for the language in which you wish to receive the names.
155
+
156
+ ```ruby
157
+ require "google/cloud/translate"
158
+
159
+ translate = Google::Cloud::Translate.new
160
+
161
+ languages = translate.languages "en"
162
+
163
+ languages.size #=> 104
164
+ languages[0].code #=> "af"
165
+ languages[0].name #=> "Afrikaans"
166
+ ```
167
+
168
+ ## Configuring retries and timeout
169
+
170
+ You can configure how many times API requests may be automatically
171
+ retried. When an API request fails, the response will be inspected to see
172
+ if the request meets criteria indicating that it may succeed on retry,
173
+ such as `500` and `503` status codes or a specific internal error code
174
+ such as `rateLimitExceeded`. If it meets the criteria, the request will be
175
+ retried after a delay. If another error occurs, the delay will be
176
+ increased before a subsequent attempt, until the `retries` limit is
177
+ reached.
178
+
179
+ You can also set the request `timeout` value in seconds.
180
+
181
+ ```ruby
182
+ require "google/cloud/translate"
183
+
184
+ translate = Google::Cloud::Translate.new retries: 10, timeout: 120
185
+ ```
@@ -0,0 +1,37 @@
1
+ # Troubleshooting
2
+
3
+ ## Where can I get more help?
4
+
5
+ ### Ask the Community
6
+
7
+ If you have a question about how to use a Google Cloud client library in your
8
+ project or are stuck in the Developer's console and don't know where to turn,
9
+ it's possible your questions have already been addressed by the community.
10
+
11
+ First, check out the appropriate tags on StackOverflow:
12
+ - [`google-cloud-platform+ruby+translate`][so-ruby]
13
+
14
+ Next, try searching through the issues on GitHub:
15
+
16
+ - [`api:translate` issues][gh-search-ruby]
17
+
18
+ Still nothing?
19
+
20
+ ### Ask the Developers
21
+
22
+ If you're experiencing a bug with the code, or have an idea for how it can be
23
+ improved, *please* create a new issue on GitHub so we can talk about it.
24
+
25
+ - [New issue][gh-ruby]
26
+
27
+ Or, you can ask questions on the [Google Cloud Platform Slack][slack-ruby]. You
28
+ can use the "ruby" channel for general Ruby questions, or use the
29
+ "google-cloud-ruby" channel if you have questions about this gem in particular.
30
+
31
+ [so-ruby]: http://stackoverflow.com/questions/tagged/google-cloud-platform+ruby+translate
32
+
33
+ [gh-search-ruby]: https://github.com/googlecloudplatform/google-cloud-ruby/issues?q=label%3A%22api%3A+translate%22
34
+
35
+ [gh-ruby]: https://github.com/googlecloudplatform/google-cloud-ruby/issues/new
36
+
37
+ [slack-ruby]: https://gcp-slack.appspot.com/
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module Translate
19
- VERSION = "1.2.2".freeze
19
+ VERSION = "1.2.3".freeze
20
20
  end
21
21
  end
22
22
  end
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: 1.2.2
4
+ version: 1.2.3
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: 2018-09-10 00:00:00.000000000 Z
12
+ date: 2018-09-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: google-cloud-core
@@ -203,8 +203,13 @@ extensions: []
203
203
  extra_rdoc_files: []
204
204
  files:
205
205
  - ".yardopts"
206
+ - AUTHENTICATION.md
207
+ - CHANGELOG.md
208
+ - CODE_OF_CONDUCT.md
209
+ - CONTRIBUTING.md
206
210
  - LICENSE
207
- - README.md
211
+ - OVERVIEW.md
212
+ - TROUBLESHOOTING.md
208
213
  - lib/google-cloud-translate.rb
209
214
  - lib/google/cloud/translate.rb
210
215
  - lib/google/cloud/translate/api.rb
data/README.md DELETED
@@ -1,104 +0,0 @@
1
- # google-cloud-translate
2
-
3
- [Google Cloud Translation API](https://cloud.google.com/translation/) ([docs](https://cloud.google.com/translation/docs)) provides a simple, programmatic interface for translating an arbitrary string into any supported language. It is highly responsive, so websites and applications can integrate with Translation API for fast, dynamic translation of source text. Language detection is also available in cases where the source language is unknown.
4
-
5
- Translation API supports more than one hundred different languages, from Afrikaans to Zulu. Used in combination, this enables translation between thousands of language pairs. Also, you can send in HTML and receive HTML with translated text back. You don't need to extract your source text or reassemble the translated content.
6
-
7
- - [google-cloud-translate API documentation](http://googlecloudplatform.github.io/google-cloud-ruby/docs/google-cloud-translate/latest)
8
- - [google-cloud-translate on RubyGems](https://rubygems.org/gems/google-cloud-translate)
9
- - [Google Cloud Translation API documentation](https://cloud.google.com/translation/docs)
10
-
11
- ## Quick Start
12
-
13
- ```sh
14
- $ gem install google-cloud-translate
15
- ```
16
-
17
- ## Authentication
18
-
19
- Like other Cloud Platform services, Google Cloud Translation API supports
20
- authentication using a project ID and OAuth 2.0 credentials. In addition,
21
- it supports authentication using a public API access key. (If both the API
22
- key and the project and OAuth 2.0 credentials are provided, the API key
23
- will be used.) Instructions and configuration options are covered in the
24
- [Authentication Guide](https://googlecloudplatform.github.io/google-cloud-ruby/docs/google-cloud-translate/latest/file.AUTHENTICATION).
25
-
26
- ## Example
27
-
28
- ```ruby
29
- require "google/cloud/translate"
30
-
31
- translate = Google::Cloud::Translate.new
32
-
33
- translation = translate.translate "Hello world!", to: "la"
34
-
35
- puts translation #=> Salve mundi!
36
-
37
- translation.from #=> "en"
38
- translation.origin #=> "Hello world!"
39
- translation.to #=> "la"
40
- translation.text #=> "Salve mundi!"
41
- ```
42
-
43
- ## Enabling Logging
44
-
45
- To enable logging for this library, set the logger for the underlying [gRPC](https://github.com/grpc/grpc/tree/master/src/ruby) library. The logger that you set may be a Ruby stdlib [`Logger`](https://ruby-doc.org/stdlib-2.5.0/libdoc/logger/rdoc/Logger.html) as shown below, or a [`Google::Cloud::Logging::Logger`](https://googlecloudplatform.github.io/google-cloud-ruby/docs/google-cloud-logging/latest/Google/Cloud/Logging/Logger) that will write logs to [Stackdriver Logging](https://cloud.google.com/logging/). See [grpc/logconfig.rb](https://github.com/grpc/grpc/blob/master/src/ruby/lib/grpc/logconfig.rb) and the gRPC [spec_helper.rb](https://github.com/grpc/grpc/blob/master/src/ruby/spec/spec_helper.rb) for additional information.
46
-
47
- Configuring a Ruby stdlib logger:
48
-
49
- ```ruby
50
- require "logger"
51
-
52
- module MyLogger
53
- LOGGER = Logger.new $stderr, level: Logger::WARN
54
- def logger
55
- LOGGER
56
- end
57
- end
58
-
59
- # Define a gRPC module-level logger method before grpc/logconfig.rb loads.
60
- module GRPC
61
- extend MyLogger
62
- end
63
- ```
64
-
65
- ## Supported Ruby Versions
66
-
67
- This library is supported on Ruby 2.3+.
68
-
69
- Google provides official support for Ruby versions that are actively supported
70
- by Ruby Core—that is, Ruby versions that are either in normal maintenance or in
71
- security maintenance, and not end of life. Currently, this means Ruby 2.3 and
72
- later. Older versions of Ruby _may_ still work, but are unsupported and not
73
- recommended. See https://www.ruby-lang.org/en/downloads/branches/ for details
74
- about the Ruby support schedule.
75
-
76
- ## Versioning
77
-
78
- This library follows [Semantic Versioning](http://semver.org/).
79
-
80
- ## Contributing
81
-
82
- Contributions to this library are always welcome and highly encouraged.
83
-
84
- See the [Contributing
85
- Guide](https://googlecloudplatform.github.io/google-cloud-ruby/docs/google-cloud-translate/latest/file.CONTRIBUTING)
86
- for more information on how to get started.
87
-
88
- Please note that this project is released with a Contributor Code of Conduct. By
89
- participating in this project you agree to abide by its terms. See [Code of
90
- Conduct](https://googlecloudplatform.github.io/google-cloud-ruby/docs/google-cloud-translate/latest/file.CODE_OF_CONDUCT)
91
- for more information.
92
-
93
- ## License
94
-
95
- This library is licensed under Apache 2.0. Full license text is available in
96
- [LICENSE](https://googlecloudplatform.github.io/google-cloud-ruby/docs/google-cloud-translate/latest/file.LICENSE).
97
-
98
- ## Support
99
-
100
- Please [report bugs at the project on
101
- Github](https://github.com/GoogleCloudPlatform/google-cloud-ruby/issues). Don't
102
- hesitate to [ask
103
- questions](http://stackoverflow.com/questions/tagged/google-cloud-platform+ruby)
104
- about the client or APIs on [StackOverflow](http://stackoverflow.com).