|
18 | 18 |
|
19 | 19 | namespace Google\Cloud\Samples\Translate; |
20 | 20 |
|
21 | | -// [START translate_translate_text] |
22 | | -use Google\Cloud\Translate\TranslateClient; |
23 | | -// [END translate_translate_text] |
24 | 21 | use Symfony\Component\Console\Command\Command; |
25 | 22 | use Symfony\Component\Console\Input\InputArgument; |
26 | 23 | use Symfony\Component\Console\Input\InputInterface; |
@@ -66,30 +63,9 @@ protected function configure() |
66 | 63 |
|
67 | 64 | protected function execute(InputInterface $input, OutputInterface $output) |
68 | 65 | { |
69 | | - $this->translate( |
70 | | - $input->getOption('api-key'), |
71 | | - $input->getArgument('text'), |
72 | | - $input->getOption('target-language'), |
73 | | - $output |
74 | | - ); |
| 66 | + $apiKey = $input->getOption('api-key'); |
| 67 | + $text = $input->getArgument('text'); |
| 68 | + $targetLanguage = $input->getOption('target-language'); |
| 69 | + require(__DIR__ . '/snippets/translate.php'); |
75 | 70 | } |
76 | | - |
77 | | - // [START translate_translate_text] |
78 | | - /** |
79 | | - * @param $apiKey string Your API key. |
80 | | - * @param $text string The text to translate. |
81 | | - * @param $targetLanguage string The target language code. |
82 | | - */ |
83 | | - protected function translate($apiKey, $text, $targetLanguage) |
84 | | - { |
85 | | - $translate = new TranslateClient([ |
86 | | - 'key' => $apiKey |
87 | | - ]); |
88 | | - $result = $translate->translate($text, [ |
89 | | - 'target' => $targetLanguage, |
90 | | - ]); |
91 | | - print("Source language: $result[source]\n"); |
92 | | - print("Translation: $result[text]\n"); |
93 | | - } |
94 | | - // [END translate_translate_text] |
95 | 71 | } |
0 commit comments