Skip to content

Commit b89d7d1

Browse files
Make Translate auth documentation clear and consistent
Additional updates prompted by #1594 / #2147.
1 parent b36bfb5 commit b89d7d1

File tree

4 files changed

+26
-24
lines changed

4 files changed

+26
-24
lines changed

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ Storage storage = StorageOptions.getDefaultInstance().getService();
177177
```
178178

179179
If no credentials are provided, `google-cloud` will attempt to detect them from the environment
180-
using `GoogleCredentials.getApplicationDefault()` which will search for Default Application
180+
using `GoogleCredentials.getApplicationDefault()` which will search for Application Default
181181
Credentials in the following locations (in order):
182182
183183
1. The credentials file pointed to by the `GOOGLE_APPLICATION_CREDENTIALS` environment variable
@@ -497,8 +497,8 @@ Google Cloud Language (Beta)
497497
498498
### Preview
499499
500-
Here is a code snippet showing a simple usage example of LanguageServiceClient. The example assumes that either default application
501-
credentials or a valid API key are available. (See [Authentication section](#authentication) for more information)
500+
Here is a code snippet showing a simple usage example of LanguageServiceClient. The example assumes that either Application Default
501+
Credentials or a valid API key are available. (See [Authentication section](#authentication) for more information)
502502
```java
503503
try (LanguageServiceClient languageServiceClient = LanguageServiceClient.create()) {
504504
Document document = Document.newBuilder().build();
@@ -515,7 +515,7 @@ Google Cloud Vision (Beta)
515515
### Preview
516516
517517
Here is a code snippet showing a simple usage example of ImageAnnotatorClient.
518-
The example assumes that either default application credentials or a valid API key
518+
The example assumes that either Application Default Credentials or a valid API key
519519
are available. (See [Authentication section](#authentication) for more information)
520520
```java
521521
try (ImageAnnotatorClient imageAnnotatorClient = ImageAnnotatorClient.create()) {
@@ -731,8 +731,8 @@ Google Translation (Beta)
731731
#### Preview
732732
733733
Here's a snippet showing a simple usage example. The example shows how to detect the language of
734-
some text and how to translate some text. The example assumes that either default application
735-
credentials or a valid API key are available. An API key stored in the `GOOGLE_API_KEY` environment
734+
some text and how to translate some text. The example assumes that either Application Default
735+
Credentials or a valid API key are available. An API key stored in the `GOOGLE_API_KEY` environment
736736
variable will be automatically detected. Complete source code can be found at
737737
[DetectLanguageAndTranslate.java](./google-cloud-examples/src/main/java/com/google/cloud/examples/translate/snippets/DetectLanguageAndTranslate.java).
738738
@@ -764,8 +764,8 @@ Google Cloud Speech (Alpha)
764764
765765
### Preview
766766
767-
Here is a code snippet showing a simple usage example of SpeechClient. The example assumes that either default application
768-
credentials or a valid API key are available. (See [Authentication section](#authentication) for more information)
767+
Here is a code snippet showing a simple usage example of SpeechClient. The example assumes that either Application Default
768+
Credentials or a valid API key are available. (See [Authentication section](#authentication) for more information)
769769
Note that you must provide a uri to a FLAC audio file to run this.
770770
771771
```java
@@ -794,8 +794,8 @@ Google Cloud Trace (Alpha)
794794
795795
### Preview
796796
797-
Here is a code snippet showing a simple usage example of TraceServiceClient. The example assumes that either default application
798-
credentials or a valid API key are available.
797+
Here is a code snippet showing a simple usage example of TraceServiceClient. The example assumes that either Application Default
798+
Credentials or a valid API key are available.
799799
Note that you must [supply credentials](#authentication) and a project ID if running this snippet elsewhere.
800800
```java
801801
try (TraceServiceClient traceServiceClient = TraceServiceClient.create()) {
@@ -812,8 +812,8 @@ Google Cloud Video Intelligence (Alpha)
812812
813813
### Preview
814814
815-
Here is a code snippet showing a simple usage example of TraceServiceClient. The example assumes that either default application
816-
credentials or a valid API key are available.
815+
Here is a code snippet showing a simple usage example of TraceServiceClient. The example assumes that either Application Default
816+
Credentials or a valid API key are available.
817817
Note that you must [supply credentials](#authentication) and a project ID if running this snippet elsewhere.
818818
```java
819819
try (VideoIntelligenceServiceClient videoIntelligenceServiceClient =

google-cloud-examples/src/main/java/com/google/cloud/examples/translate/snippets/DetectLanguageAndTranslate.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ public class DetectLanguageAndTranslate {
3737
public static void main(String... args) {
3838
// Create a service object
3939
//
40-
// Requests are authenticated using default application credentials if available; otherwise,
41-
// using an API key from the GOOGLE_API_KEY environment variable
40+
// If no explicit credentials or API key are set, requests are authenticated using Application
41+
// Default Credentials if available; otherwise, using an API key from the GOOGLE_API_KEY
42+
// environment variable
4243
Translate translate = TranslateOptions.getDefaultInstance().getService();
4344

4445
// Detect the language of some text

google-cloud-translate/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ section to add `google-cloud-translate` as a dependency in your code.
8080

8181
#### Creating an authorized service object
8282
To make authenticated requests to Google Translation, you must create a service object with
83-
credentials or with an API key. The simplest way to authenticate is to use
83+
credentials or use an API key. The simplest way to authenticate is to use
8484
[Application Default Credentials](https://developers.google.com/identity/protocols/application-default-credentials).
8585
These credentials are automatically inferred from your environment, so you only need the following
8686
code to create your service object:
@@ -142,8 +142,8 @@ Translation translation = translate.translate(
142142

143143
In
144144
[DetectLanguageAndTranslate.java](../google-cloud-examples/src/main/java/com/google/cloud/examples/translate/snippets/DetectLanguageAndTranslate.java)
145-
we put together all the code shown above into one program. The program assumes that either default
146-
application credentials or a valid api key are available.
145+
we put together all the code shown above into one program. The program assumes that either Application
146+
Default Credentials or a valid API key are available.
147147

148148
Troubleshooting
149149
---------------

google-cloud-translate/src/main/java/com/google/cloud/translate/package-info.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818
* A client to Google Translation.
1919
*
2020
* <p>Here's a simple usage example for using google-cloud. This example shows how to detect the
21-
* language of some text and how to translate some text. The example assumes that the
22-
* {@code GOOGLE_API_KEY} is set and contains a valid API key. Alternatively, you can use
21+
* language of some text and how to translate some text. The example assumes that either Application
22+
* Default Credentials are available or that the {@code GOOGLE_API_KEY} environment variable is set
23+
* and contains a valid API key. Alternatively, you can use
24+
* {@link ServiceOptions.Builder#setCredentials setCredentials} to set credentials, or
2325
* {@link com.google.cloud.translate.TranslateOptions.Builder#setApiKey(java.lang.String)} to set
24-
* the API key. For the complete source code see
25-
* <a href="https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-examples/src/main/java/com/google/cloud/examples/translate/snippets/DetectLanguageAndTranslate.java">
26-
* DetectLanguageAndTranslate.java</a>.
27-
* <pre> {@code
28-
* Translate translate = TranslateOptions.getDefaultInstance().getService();
26+
* an API key. For the complete source code see <a
27+
* href="https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-examples/src/main/java/com/google/cloud/examples/translate/snippets/DetectLanguageAndTranslate.java">
28+
* DetectLanguageAndTranslate.java</a>. <pre>
29+
* {@code Translate translate = TranslateOptions.getDefaultInstance().getService();
2930
*
3031
* Detection detection = translate.detect("Hola");
3132
* String detectedLanguage = detection.getLanguage();

0 commit comments

Comments
 (0)