Skip to content

Commit 9c839cd

Browse files
committed
Translate API no longer requires an API key.
1 parent 41db8e8 commit 9c839cd

15 files changed

+68
-117
lines changed

translate/api/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "google/translate-sample",
33
"type": "project",
44
"require": {
5-
"google/cloud": "^0.11.1",
5+
"google/cloud": "^0.13",
66
"symfony/console": "^3.1"
77
},
88
"autoload": {

translate/api/composer.lock

Lines changed: 28 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

translate/api/src/DetectLanguageCommand.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
use Symfony\Component\Console\Command\Command;
2222
use Symfony\Component\Console\Input\InputArgument;
23-
use Symfony\Component\Console\Input\InputOption;
2423
use Symfony\Component\Console\Input\InputInterface;
2524
use Symfony\Component\Console\Output\OutputInterface;
2625

@@ -38,7 +37,7 @@ protected function configure()
3837
->setHelp(<<<EOF
3938
The <info>%command.name%</info> command detects which language text was written in using the Google Cloud Translate API.
4039
41-
<info>php %command.full_name% -k YOUR-API-KEY "Your text here"</info>
40+
<info>php %command.full_name% "Your text here"</info>
4241
4342
EOF
4443
)
@@ -47,18 +46,11 @@ protected function configure()
4746
InputArgument::REQUIRED,
4847
'The text to examine.'
4948
)
50-
->addOption(
51-
'api-key',
52-
'k',
53-
InputOption::VALUE_REQUIRED,
54-
'Your API key.'
55-
)
5649
;
5750
}
5851

5952
protected function execute(InputInterface $input, OutputInterface $output)
6053
{
61-
$apiKey = $input->getOption('api-key');
6254
$text = $input->getArgument('text');
6355
require(__DIR__ . '/snippets/detect_language.php');
6456
}

translate/api/src/ListCodesCommand.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
use Symfony\Component\Console\Command\Command;
2222
use Symfony\Component\Console\Input\InputInterface;
23-
use Symfony\Component\Console\Input\InputOption;
2423
use Symfony\Component\Console\Output\OutputInterface;
2524

2625
/**
@@ -37,22 +36,15 @@ protected function configure()
3736
->setHelp(<<<EOF
3837
The <info>%command.name%</info> command lists all the language codes in the Google Cloud Translate API.
3938
40-
<info>php %command.full_name% -k YOUR-API-KEY</info>
39+
<info>php %command.full_name%</info>
4140
4241
EOF
4342
)
44-
->addOption(
45-
'api-key',
46-
'k',
47-
InputOption::VALUE_REQUIRED,
48-
'Your API key.'
49-
)
5043
;
5144
}
5245

5346
protected function execute(InputInterface $input, OutputInterface $output)
5447
{
55-
$apiKey = $input->getOption('api-key');
5648
require(__DIR__ . '/snippets/list_codes.php');
5749
}
5850
}

translate/api/src/ListLanguagesCommand.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,10 @@ protected function configure()
3737
->setHelp(<<<EOF
3838
The <info>%command.name%</info> lists language codes and names in the Google Cloud Translate API.
3939
40-
<info>php %command.full_name% -k YOUR-API-KEY -t en</info>
40+
<info>php %command.full_name% -t en</info>
4141
4242
EOF
4343
)
44-
->addOption(
45-
'api-key',
46-
'k',
47-
InputOption::VALUE_REQUIRED,
48-
'Your API key.'
49-
)
5044
->addOption(
5145
'target-language',
5246
't',
@@ -58,7 +52,6 @@ protected function configure()
5852

5953
protected function execute(InputInterface $input, OutputInterface $output)
6054
{
61-
$apiKey = $input->getOption('api-key');
6255
$targetLanguage = $input->getOption('target-language');
6356
require(__DIR__ . '/snippets/list_languages.php');
6457
}

translate/api/src/TranslateCommand.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,10 @@ protected function configure()
3737
->setHelp(<<<EOF
3838
The <info>%command.name%</info> command transcribes audio using the Google Cloud Translate API.
3939
40-
<info>php %command.full_name% -k YOUR-API-KEY -t ja "Hello World."</info>
40+
<info>php %command.full_name% -t ja "Hello World."</info>
4141
4242
EOF
4343
)
44-
->addOption(
45-
'api-key',
46-
'k',
47-
InputOption::VALUE_REQUIRED,
48-
'Your API key.'
49-
)
5044
->addArgument(
5145
'text',
5246
InputArgument::REQUIRED,
@@ -63,7 +57,6 @@ protected function configure()
6357

6458
protected function execute(InputInterface $input, OutputInterface $output)
6559
{
66-
$apiKey = $input->getOption('api-key');
6760
$text = $input->getArgument('text');
6861
$targetLanguage = $input->getOption('target-language');
6962
require(__DIR__ . '/snippets/translate.php');

translate/api/src/snippets/detect_language.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,9 @@
1919
// [START translate_detect_language]
2020
use Google\Cloud\Translate\TranslateClient;
2121

22-
// $apiKey = 'YOUR-API-KEY';
2322
// $text = 'The text whose language to detect. This will be detected as en.';
2423

25-
$translate = new TranslateClient([
26-
'key' => $apiKey,
27-
]);
24+
$translate = new TranslateClient();
2825
$result = $translate->detectLanguage($text);
2926
print("Language code: $result[languageCode]\n");
3027
print("Confidence: $result[confidence]\n");

translate/api/src/snippets/list_codes.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@
1919
// [START translate_list_codes]
2020
use Google\Cloud\Translate\TranslateClient;
2121

22-
// $apiKey = 'YOUR-API-KEY';
23-
24-
$translate = new TranslateClient([
25-
'key' => $apiKey,
26-
]);
22+
$translate = new TranslateClient();
2723
foreach ($translate->languages() as $code) {
2824
print("$code\n");
2925
}

translate/api/src/snippets/list_languages.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,9 @@
2121
// [START translate_list_language_names]
2222
use Google\Cloud\Translate\TranslateClient;
2323

24-
// $apiKey = 'YOUR-API-KEY'
2524
// $targetLanguage = 'en'; // Print the names of the languages in which language?
2625
27-
$translate = new TranslateClient([
28-
'key' => $apiKey,
29-
]);
26+
$translate = new TranslateClient();
3027
$result = $translate->localizedLanguages([
3128
'target' => $targetLanguage,
3229
]);

translate/api/src/snippets/translate.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,10 @@
2121
// [START translate_translate_text]
2222
use Google\Cloud\Translate\TranslateClient;
2323

24-
// $apiKey = 'YOUR-API-KEY'
2524
// $text = 'The text to translate."
2625
// $targetLanguage = 'ja'; // Which language to translate to?
2726
28-
$translate = new TranslateClient([
29-
'key' => $apiKey
30-
]);
27+
$translate = new TranslateClient();
3128
$result = $translate->translate($text, [
3229
'target' => $targetLanguage,
3330
]);

0 commit comments

Comments
 (0)