Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translate API no longer requires an API key. #248

Merged
merged 1 commit into from
Nov 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion translate/api/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "google/translate-sample",
"type": "project",
"require": {
"google/cloud": "^0.11.1",
"google/cloud": "^0.13",
"symfony/console": "^3.1"
},
"autoload": {
Expand Down
53 changes: 28 additions & 25 deletions translate/api/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 1 addition & 9 deletions translate/api/src/DetectLanguageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

Expand All @@ -38,7 +37,7 @@ protected function configure()
->setHelp(<<<EOF
The <info>%command.name%</info> command detects which language text was written in using the Google Cloud Translate API.

<info>php %command.full_name% -k YOUR-API-KEY "Your text here"</info>
<info>php %command.full_name% "Your text here"</info>

EOF
)
Expand All @@ -47,18 +46,11 @@ protected function configure()
InputArgument::REQUIRED,
'The text to examine.'
)
->addOption(
'api-key',
'k',
InputOption::VALUE_REQUIRED,
'Your API key.'
)
;
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$apiKey = $input->getOption('api-key');
$text = $input->getArgument('text');
require(__DIR__ . '/snippets/detect_language.php');
}
Expand Down
10 changes: 1 addition & 9 deletions translate/api/src/ListCodesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

/**
Expand All @@ -37,22 +36,15 @@ protected function configure()
->setHelp(<<<EOF
The <info>%command.name%</info> command lists all the language codes in the Google Cloud Translate API.

<info>php %command.full_name% -k YOUR-API-KEY</info>
<info>php %command.full_name%</info>

EOF
)
->addOption(
'api-key',
'k',
InputOption::VALUE_REQUIRED,
'Your API key.'
)
;
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$apiKey = $input->getOption('api-key');
require(__DIR__ . '/snippets/list_codes.php');
}
}
9 changes: 1 addition & 8 deletions translate/api/src/ListLanguagesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,10 @@ protected function configure()
->setHelp(<<<EOF
The <info>%command.name%</info> lists language codes and names in the Google Cloud Translate API.

<info>php %command.full_name% -k YOUR-API-KEY -t en</info>
<info>php %command.full_name% -t en</info>

EOF
)
->addOption(
'api-key',
'k',
InputOption::VALUE_REQUIRED,
'Your API key.'
)
->addOption(
'target-language',
't',
Expand All @@ -58,7 +52,6 @@ protected function configure()

protected function execute(InputInterface $input, OutputInterface $output)
{
$apiKey = $input->getOption('api-key');
$targetLanguage = $input->getOption('target-language');
require(__DIR__ . '/snippets/list_languages.php');
}
Expand Down
9 changes: 1 addition & 8 deletions translate/api/src/TranslateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,10 @@ protected function configure()
->setHelp(<<<EOF
The <info>%command.name%</info> command transcribes audio using the Google Cloud Translate API.

<info>php %command.full_name% -k YOUR-API-KEY -t ja "Hello World."</info>
<info>php %command.full_name% -t ja "Hello World."</info>

EOF
)
->addOption(
'api-key',
'k',
InputOption::VALUE_REQUIRED,
'Your API key.'
)
->addArgument(
'text',
InputArgument::REQUIRED,
Expand All @@ -63,7 +57,6 @@ protected function configure()

protected function execute(InputInterface $input, OutputInterface $output)
{
$apiKey = $input->getOption('api-key');
$text = $input->getArgument('text');
$targetLanguage = $input->getOption('target-language');
require(__DIR__ . '/snippets/translate.php');
Expand Down
5 changes: 1 addition & 4 deletions translate/api/src/snippets/detect_language.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@
// [START translate_detect_language]
use Google\Cloud\Translate\TranslateClient;

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

$translate = new TranslateClient([
'key' => $apiKey,
]);
$translate = new TranslateClient();
$result = $translate->detectLanguage($text);
print("Language code: $result[languageCode]\n");
print("Confidence: $result[confidence]\n");
Expand Down
6 changes: 1 addition & 5 deletions translate/api/src/snippets/list_codes.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@
// [START translate_list_codes]
use Google\Cloud\Translate\TranslateClient;

// $apiKey = 'YOUR-API-KEY';

$translate = new TranslateClient([
'key' => $apiKey,
]);
$translate = new TranslateClient();
foreach ($translate->languages() as $code) {
print("$code\n");
}
Expand Down
5 changes: 1 addition & 4 deletions translate/api/src/snippets/list_languages.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,9 @@
// [START translate_list_language_names]
use Google\Cloud\Translate\TranslateClient;

// $apiKey = 'YOUR-API-KEY'
// $targetLanguage = 'en'; // Print the names of the languages in which language?

$translate = new TranslateClient([
'key' => $apiKey,
]);
$translate = new TranslateClient();
$result = $translate->localizedLanguages([
'target' => $targetLanguage,
]);
Expand Down
5 changes: 1 addition & 4 deletions translate/api/src/snippets/translate.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,10 @@
// [START translate_translate_text]
use Google\Cloud\Translate\TranslateClient;

// $apiKey = 'YOUR-API-KEY'
// $text = 'The text to translate."
// $targetLanguage = 'ja'; // Which language to translate to?

$translate = new TranslateClient([
'key' => $apiKey
]);
$translate = new TranslateClient();
$result = $translate->translate($text, [
'target' => $targetLanguage,
]);
Expand Down
Loading