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

feat: [Translate] Adds AdaptiveMt HTML/Glossary support #7582

Merged
merged 2 commits into from
Aug 9, 2024
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
Binary file modified Translate/metadata/V3/AdaptiveMt.php
Binary file not shown.
Binary file added Translate/metadata/V3/AutomlTranslation.php
Binary file not shown.
Binary file modified Translate/metadata/V3/Common.php
Binary file not shown.
Binary file modified Translate/metadata/V3/TranslationService.php
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
* `projects/{project}/locations/{location-id}/adaptiveMtDatasets/{dataset}`
* Please see {@see TranslationServiceClient::adaptiveMtDatasetName()} for help formatting this field.
* @param string $contentElement The content of the input in string format.
* For now only one sentence per request is supported.
*/
function adaptive_mt_translate_sample(
string $formattedParent,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/

require_once __DIR__ . '/../../../vendor/autoload.php';

// [START translate_v3_generated_TranslationService_CreateDataset_sync]
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Translate\V3\Client\TranslationServiceClient;
use Google\Cloud\Translate\V3\CreateDatasetRequest;
use Google\Cloud\Translate\V3\Dataset;
use Google\Rpc\Status;

/**
* Creates a Dataset.
*
* @param string $formattedParent The project name. Please see
* {@see TranslationServiceClient::locationName()} for help formatting this field.
*/
function create_dataset_sample(string $formattedParent): void
{
// Create a client.
$translationServiceClient = new TranslationServiceClient();

// Prepare the request message.
$dataset = new Dataset();
$request = (new CreateDatasetRequest())
->setParent($formattedParent)
->setDataset($dataset);

// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $translationServiceClient->createDataset($request);
$response->pollUntilComplete();

if ($response->operationSucceeded()) {
/** @var Dataset $result */
$result = $response->getResult();
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
} else {
/** @var Status $error */
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}

/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedParent = TranslationServiceClient::locationName('[PROJECT]', '[LOCATION]');

create_dataset_sample($formattedParent);
}
// [END translate_v3_generated_TranslationService_CreateDataset_sync]
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/

require_once __DIR__ . '/../../../vendor/autoload.php';

// [START translate_v3_generated_TranslationService_CreateGlossaryEntry_sync]
use Google\ApiCore\ApiException;
use Google\Cloud\Translate\V3\Client\TranslationServiceClient;
use Google\Cloud\Translate\V3\CreateGlossaryEntryRequest;
use Google\Cloud\Translate\V3\GlossaryEntry;

/**
* Creates a glossary entry.
*
* @param string $formattedParent The resource name of the glossary to create the entry under. Please see
* {@see TranslationServiceClient::glossaryName()} for help formatting this field.
*/
function create_glossary_entry_sample(string $formattedParent): void
{
// Create a client.
$translationServiceClient = new TranslationServiceClient();

// Prepare the request message.
$glossaryEntry = new GlossaryEntry();
$request = (new CreateGlossaryEntryRequest())
->setParent($formattedParent)
->setGlossaryEntry($glossaryEntry);

// Call the API and handle any network failures.
try {
/** @var GlossaryEntry $response */
$response = $translationServiceClient->createGlossaryEntry($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}

/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedParent = TranslationServiceClient::glossaryName('[PROJECT]', '[LOCATION]', '[GLOSSARY]');

create_glossary_entry_sample($formattedParent);
}
// [END translate_v3_generated_TranslationService_CreateGlossaryEntry_sync]
86 changes: 86 additions & 0 deletions Translate/samples/V3/TranslationServiceClient/create_model.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/

require_once __DIR__ . '/../../../vendor/autoload.php';

// [START translate_v3_generated_TranslationService_CreateModel_sync]
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Translate\V3\Client\TranslationServiceClient;
use Google\Cloud\Translate\V3\CreateModelRequest;
use Google\Cloud\Translate\V3\Model;
use Google\Rpc\Status;

/**
* Creates a Model.
*
* @param string $formattedParent The project name, in form of
* `projects/{project}/locations/{location}`
* Please see {@see TranslationServiceClient::locationName()} for help formatting this field.
*/
function create_model_sample(string $formattedParent): void
{
// Create a client.
$translationServiceClient = new TranslationServiceClient();

// Prepare the request message.
$model = new Model();
$request = (new CreateModelRequest())
->setParent($formattedParent)
->setModel($model);

// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $translationServiceClient->createModel($request);
$response->pollUntilComplete();

if ($response->operationSucceeded()) {
/** @var Model $result */
$result = $response->getResult();
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
} else {
/** @var Status $error */
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}

/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedParent = TranslationServiceClient::locationName('[PROJECT]', '[LOCATION]');

create_model_sample($formattedParent);
}
// [END translate_v3_generated_TranslationService_CreateModel_sync]
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/

require_once __DIR__ . '/../../../vendor/autoload.php';

// [START translate_v3_generated_TranslationService_DeleteDataset_sync]
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Translate\V3\Client\TranslationServiceClient;
use Google\Cloud\Translate\V3\DeleteDatasetRequest;
use Google\Rpc\Status;

/**
* Deletes a dataset and all of its contents.
*
* @param string $formattedName The name of the dataset to delete. Please see
* {@see TranslationServiceClient::datasetName()} for help formatting this field.
*/
function delete_dataset_sample(string $formattedName): void
{
// Create a client.
$translationServiceClient = new TranslationServiceClient();

// Prepare the request message.
$request = (new DeleteDatasetRequest())
->setName($formattedName);

// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $translationServiceClient->deleteDataset($request);
$response->pollUntilComplete();

if ($response->operationSucceeded()) {
printf('Operation completed successfully.' . PHP_EOL);
} else {
/** @var Status $error */
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}

/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedName = TranslationServiceClient::datasetName('[PROJECT]', '[LOCATION]', '[DATASET]');

delete_dataset_sample($formattedName);
}
// [END translate_v3_generated_TranslationService_DeleteDataset_sync]
Loading
Loading