{"id":13405108,"url":"https://github.com/googleapis/google-cloud-php-translate","last_synced_at":"2025-05-16T08:03:31.442Z","repository":{"id":37412733,"uuid":"83372886","full_name":"googleapis/google-cloud-php-translate","owner":"googleapis","description":null,"archived":false,"fork":false,"pushed_at":"2024-05-03T18:41:09.000Z","size":350,"stargazers_count":183,"open_issues_count":0,"forks_count":27,"subscribers_count":56,"default_branch":"main","last_synced_at":"2024-05-18T15:44:59.156Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/googleapis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-02-28T00:52:55.000Z","updated_at":"2024-06-01T04:31:36.532Z","dependencies_parsed_at":"2022-08-08T20:15:38.075Z","dependency_job_id":"94b7acd2-a4de-49f7-8b13-91ade87c0ea9","html_url":"https://github.com/googleapis/google-cloud-php-translate","commit_stats":{"total_commits":110,"total_committers":14,"mean_commits":7.857142857142857,"dds":0.8181818181818181,"last_synced_commit":"ee6cab6187b08de549fd6c77af30fa4c75074ddd"},"previous_names":[],"tags_count":78,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/googleapis%2Fgoogle-cloud-php-translate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/googleapis%2Fgoogle-cloud-php-translate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/googleapis%2Fgoogle-cloud-php-translate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/googleapis%2Fgoogle-cloud-php-translate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/googleapis","download_url":"https://codeload.github.com/googleapis/google-cloud-php-translate/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254493381,"owners_count":22080126,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T19:01:55.833Z","updated_at":"2025-05-16T08:03:31.397Z","avatar_url":"https://github.com/googleapis.png","language":"PHP","readme":"# Google Cloud Translation for PHP\n\n\u003e Idiomatic PHP client for [Translation](https://cloud.google.com/translate/).\n\n[![Latest Stable Version](https://poser.pugx.org/google/cloud-translate/v/stable)](https://packagist.org/packages/google/cloud-translate) [![Packagist](https://img.shields.io/packagist/dm/google/cloud-translate.svg)](https://packagist.org/packages/google/cloud-translate)\n\n* [API documentation](https://cloud.google.com/php/docs/reference/cloud-translate/latest)\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```sh\n$ composer require google/cloud-translate\n```\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```php\nGoogle\\ApiCore\\ApiException;\nGoogle\\Cloud\\Translate\\V3\\AdaptiveMtDataset;\nGoogle\\Cloud\\Translate\\V3\\Client\\TranslationServiceClient;\nGoogle\\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.\ntry {\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``` Using the Handwritten Client (Interacts with the V2 API)\n\n```php\nrequire 'vendor/autoload.php';\n\nuse Google\\Cloud\\Translate\\V2\\TranslateClient;\n\n$translate = new TranslateClient([\n    'key' =\u003e 'your_key'\n]);\n\n// Translate text from english to french.\n$result = $translate-\u003etranslate('Hello world!', [\n    'target' =\u003e 'fr'\n]);\n\necho $result['text'] . \"\\n\";\n\n// Detect the language of a string.\n$result = $translate-\u003edetectLanguage('Greetings from Michigan!');\n\necho $result['languageCode'] . \"\\n\";\n\n// Get the languages supported for translation specifically for your target language.\n$languages = $translate-\u003elocalizedLanguages([\n    'target' =\u003e 'en'\n]);\n\nforeach ($languages as $language) {\n    echo $language['name'] . \"\\n\";\n    echo $language['code'] . \"\\n\";\n}\n\n// Get all languages supported for translation.\n$languages = $translate-\u003elanguages();\n\nforeach ($languages as $language) {\n    echo $language . \"\\n\";\n}\n```\n\n### Sample\n\n```php\nGoogle\\ApiCore\\ApiException;\nGoogle\\Cloud\\Translate\\V3\\AdaptiveMtDataset;\nGoogle\\Cloud\\Translate\\V3\\Client\\TranslationServiceClient;\nGoogle\\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.\ntry {\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``` Using the Generated Client (Interacts with the V3 API)\n\n```php\nrequire 'vendor/autoload.php';\n\nuse 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\nforeach ($response-\u003egetTranslations() as $key =\u003e $translation) {\n    $separator = $key === 2\n        ? '!'\n        : ', ';\n    echo $translation-\u003egetTranslatedText() . $separator;\n}\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 \u0026 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/).\n","funding_links":[],"categories":["PHP"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoogleapis%2Fgoogle-cloud-php-translate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoogleapis%2Fgoogle-cloud-php-translate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoogleapis%2Fgoogle-cloud-php-translate/lists"}