NOTE: This repository is part of Google Cloud PHP. Any
support requests, bug reports, or development contributions should be directed to
that project.
Dynamically translates text between thousands of language pairs. The Cloud
Translation API lets websites and programs integrate with the translation
service programmatically. The Google Translation API is part of the larger Cloud
Machine Learning API family.
Installation
To begin, install the preferred dependency manager for PHP, Composer.
Now install this component:
$ composer require google/cloud-translate
Authentication
Please see our Authentication guide for more information
on authenticating your client. Once authenticated, you'll be ready to start making requests.
Sample
Google\ApiCore\ApiException;
Google\Cloud\Translate\V3\AdaptiveMtDataset;
Google\Cloud\Translate\V3\Client\TranslationServiceClient;
Google\Cloud\Translate\V3\GetAdaptiveMtDatasetRequest;
// Create a client.
$translationServiceClient = new TranslationServiceClient();
// Prepare the request message.
$request = (new GetAdaptiveMtDatasetRequest())
->setName($formattedName);
// Call the API and handle any network failures.
try {
/** @var AdaptiveMtDataset $response */
$response = $translationServiceClient->getAdaptiveMtDataset($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
Using the Generated Client (Interacts with the V3 API)
This component offers both a handwritten and generated client, used to access the V2 and V3 translation APIs, respectively.
Both clients will receive on-going support and feature additions, however, it is worth noting the streamlined nature of
the generated client means it will receive updates more frequently. Additionally, the generated client is capable of
utilizing gRPC for its transport (by installing the gRPC extension) while the handwritten client interacts over
REST & HTTP/1.1 only.
The handwritten client can be found under Google\Cloud\Translate\TranslateClient, whereas the generated client is
found under Google\Cloud\Translate\V3\TranslationServiceClient.
Debugging
Please see our Debugging guide
for more information about the debugging tools.
Version
This component is considered GA (generally available). As such, it will not introduce backwards-incompatible changes in
any minor or patch releases. We will address issues and requests with the highest priority.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[],[],null,["Version latestkeyboard_arrow_down\n\n- [2.0.3 (latest)](/php/docs/reference/cloud-translate/latest)\n- [2.0.2](/php/docs/reference/cloud-translate/2.0.2)\n- [1.21.0](/php/docs/reference/cloud-translate/1.21.0)\n- [1.20.2](/php/docs/reference/cloud-translate/1.20.2)\n- [1.19.0](/php/docs/reference/cloud-translate/1.19.0)\n- [1.18.1](/php/docs/reference/cloud-translate/1.18.1)\n- [1.17.7](/php/docs/reference/cloud-translate/1.17.7)\n- [1.16.0](/php/docs/reference/cloud-translate/1.16.0)\n- [1.15.4](/php/docs/reference/cloud-translate/1.15.4)\n- [1.14.3](/php/docs/reference/cloud-translate/1.14.3)\n- [1.13.3](/php/docs/reference/cloud-translate/1.13.3)\n- [1.12.12](/php/docs/reference/cloud-translate/1.12.12) \n\nGoogle Cloud Translation for PHP\n================================\n\n\u003e Idiomatic PHP client for [Translation](https://cloud.google.com/translate/).\n\n[](https://packagist.org/packages/google/cloud-translate) [](https://packagist.org/packages/google/cloud-translate)\n\n**NOTE:** This repository is part of [Google Cloud PHP](https://github.com/googleapis/google-cloud-php). Any\nsupport requests, bug reports, or development contributions should be directed to\nthat project.\n\nDynamically translates text between thousands of language pairs. The Cloud\nTranslation API lets websites and programs integrate with the translation\nservice programmatically. The Google Translation API is part of the larger Cloud\nMachine Learning API family.\n\n### Installation\n\nTo begin, install the preferred dependency manager for PHP, [Composer](https://getcomposer.org/).\n\nNow install this component: \n\n $ composer require google/cloud-translate\n\n### Authentication\n\nPlease see our [Authentication guide](https://github.com/googleapis/google-cloud-php/blob/main/AUTHENTICATION.md) for more information\non authenticating your client. Once authenticated, you'll be ready to start making requests.\n\n### Sample\n\n Google\\ApiCore\\ApiException;\n Google\\Cloud\\Translate\\V3\\AdaptiveMtDataset;\n Google\\Cloud\\Translate\\V3\\Client\\TranslationServiceClient;\n Google\\Cloud\\Translate\\V3\\GetAdaptiveMtDatasetRequest;\n\n // Create a client.\n $translationServiceClient = new TranslationServiceClient();\n\n // Prepare the request message.\n $request = (new GetAdaptiveMtDatasetRequest())\n -\u003esetName($formattedName);\n\n // Call the API and handle any network failures.\n try {\n /** @var AdaptiveMtDataset $response */\n $response = $translationServiceClient-\u003egetAdaptiveMtDataset($request);\n printf('Response data: %s' . PHP_EOL, $response-\u003eserializeToJsonString());\n } catch (ApiException $ex) {\n printf('Call failed with message: %s' . PHP_EOL, $ex-\u003egetMessage());\n }\n\n### Using the Generated Client (Interacts with the V3 API)\n\n require 'vendor/autoload.php';\n\n use Google\\Cloud\\Translate\\V3\\TranslationServiceClient;\n\n $translationClient = new TranslationServiceClient();\n $content = ['one', 'two', 'three'];\n $targetLanguage = 'es';\n $response = $translationClient-\u003etranslateText(\n $content,\n $targetLanguage,\n TranslationServiceClient::locationName('[PROJECT_ID]', 'global')\n );\n\n foreach ($response-\u003egetTranslations() as $key =\u003e $translation) {\n $separator = $key === 2\n ? '!'\n : ', ';\n echo $translation-\u003egetTranslatedText() . $separator;\n }\n\n### Choosing the Right Client for You\n\nThis component offers both a handwritten and generated client, used to access the V2 and V3 translation APIs, respectively.\nBoth clients will receive on-going support and feature additions, however, it is worth noting the streamlined nature of\nthe generated client means it will receive updates more frequently. Additionally, the generated client is capable of\nutilizing gRPC for its transport (by installing the gRPC extension) while the handwritten client interacts over\nREST \\& HTTP/1.1 only.\n\nThe handwritten client can be found under `Google\\Cloud\\Translate\\TranslateClient`, whereas the generated client is\nfound under `Google\\Cloud\\Translate\\V3\\TranslationServiceClient`.\n\n### Debugging\n\nPlease see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md)\nfor more information about the debugging tools.\n\n### Version\n\nThis component is considered GA (generally available). As such, it will not introduce backwards-incompatible changes in\nany minor or patch releases. We will address issues and requests with the highest priority.\n\n### Next Steps\n\n1. Understand the [official documentation](https://cloud.google.com/translation/docs/).\n2. Take a look at [in-depth usage samples](https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/translate/)."]]