Skip to content

Commit 86eeac3

Browse files
authored
fixes translate sample README and tests (GoogleCloudPlatform#849)
1 parent 6ccd02e commit 86eeac3

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

translate/README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,13 @@ https://cloud.google.com/translate/).
1313
## Build and Run
1414
1. **Enable APIs** - [Enable the Translate API](https://console.cloud.google.com/flows/enableapi?apiid=translate)
1515
and create a new project or select an existing project.
16-
2. **Download The Credentials** - Click "Go to credentials" after enabling the APIs. Click "Create Credentials"
17-
and select "API key". Copy the API key.
16+
2. **Download The Credentials** - Configure your project using [Application Default Credentials][adc].
17+
Click "Go to credentials" after enabling the APIs. Click "Create Credentials"
18+
and select "Service Account Credentials" and download the credentials file. Then set the path to
19+
this file to the environment variable `GOOGLE_APPLICATION_CREDENTIALS`:
20+
```
21+
$ export GOOGLE_APPLICATION_CREDENTIALS=/path/to/credentials.json
22+
```
1823
3. **Clone the repo** and cd into this directory
1924
```
2025
$ git clone https://github.com/GoogleCloudPlatform/php-docs-samples
@@ -58,3 +63,5 @@ Available commands:
5863
## Licensing
5964

6065
* See [LICENSE](../LICENSE)
66+
67+
[adc]: https://cloud.google.com/docs/authentication/production#obtaining_and_providing_service_account_credentials_manually

translate/test/quickstartTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ public function testQuickstart()
2121
if (!$projectId = getenv('GOOGLE_PROJECT_ID')) {
2222
$this->markTestSkipped('GOOGLE_PROJECT_ID must be set.');
2323
}
24+
if (!getenv('GOOGLE_APPLICATION_CREDENTIALS')) {
25+
$this->markTestSkipped('GOOGLE_APPLICATION_CREDENTIALS must be set.');
26+
}
2427

2528
$file = sys_get_temp_dir() . '/translate_quickstart.php';
2629
$contents = file_get_contents(__DIR__ . '/../quickstart.php');

0 commit comments

Comments
 (0)