|
18 | 18 | namespace Google\Cloud\Samples\Translate; |
19 | 19 |
|
20 | 20 | // [START translate_v3_batch_translate_text_with_glossary_and_model] |
| 21 | +use Google\Cloud\Translate\V3\BatchTranslateTextRequest; |
| 22 | +use Google\Cloud\Translate\V3\Client\TranslationServiceClient; |
21 | 23 | use Google\Cloud\Translate\V3\GcsDestination; |
22 | 24 | use Google\Cloud\Translate\V3\GcsSource; |
23 | 25 | use Google\Cloud\Translate\V3\InputConfig; |
24 | 26 | use Google\Cloud\Translate\V3\OutputConfig; |
25 | 27 | use Google\Cloud\Translate\V3\TranslateTextGlossaryConfig; |
26 | | -use Google\Cloud\Translate\V3\TranslationServiceClient; |
27 | 28 |
|
28 | 29 | /** |
29 | 30 | * @param string $inputUri Path to to source input (e.g. "gs://cloud-samples-data/text.txt"). |
@@ -79,17 +80,15 @@ function v3_batch_translate_text_with_glossary_and_model( |
79 | 80 | $glossaries = ['ja' => $glossariesItem]; |
80 | 81 |
|
81 | 82 | try { |
82 | | - $operationResponse = $translationServiceClient->batchTranslateText( |
83 | | - $formattedParent, |
84 | | - $sourceLanguage, |
85 | | - $targetLanguageCodes, |
86 | | - $inputConfigs, |
87 | | - $outputConfig, |
88 | | - [ |
89 | | - 'models' => $models, |
90 | | - 'glossaries' => $glossaries |
91 | | - ] |
92 | | - ); |
| 83 | + $request = (new BatchTranslateTextRequest()) |
| 84 | + ->setParent($formattedParent) |
| 85 | + ->setSourceLanguageCode($sourceLanguage) |
| 86 | + ->setTargetLanguageCodes($targetLanguageCodes) |
| 87 | + ->setInputConfigs($inputConfigs) |
| 88 | + ->setOutputConfig($outputConfig) |
| 89 | + ->setModels($models) |
| 90 | + ->setGlossaries($glossaries); |
| 91 | + $operationResponse = $translationServiceClient->batchTranslateText($request); |
93 | 92 | $operationResponse->pollUntilComplete(); |
94 | 93 | if ($operationResponse->operationSucceeded()) { |
95 | 94 | $response = $operationResponse->getResult(); |
|
0 commit comments