google / cloud-translate
Cloud Translation Client for PHP
Requires
- php: ^8.0
- google/cloud-core: ^1.57
- google/gax: ^1.36.0
Requires (Dev)
- erusev/parsedown: ^1.6
- phpdocumentor/reflection: ^5.3.3||^6.0
- phpdocumentor/reflection-docblock: ^5.3
- phpspec/prophecy-phpunit: ^2.0
- phpunit/phpunit: ^9.0
- squizlabs/php_codesniffer: 2.*
Suggests
- ext-grpc: The gRPC extension enables use of the performant gRPC transport
- ext-protobuf: Provides a significant increase in throughput over the pure PHP protobuf implementation. See https://cloud.google.com/php/grpc for installation instructions.
- dev-main
- v1.20.1
- v1.20.0
- v1.19.0
- v1.18.1
- v1.18.0
- v1.17.7
- v1.17.6
- v1.17.5
- v1.17.4
- v1.17.3
- v1.17.2
- v1.17.1
- v1.17.0
- v1.16.0
- v1.15.4
- v1.15.3
- v1.15.2
- v1.15.1
- v1.15.0
- v1.14.3
- v1.14.2
- v1.14.1
- v1.14.0
- v1.13.3
- v1.13.2
- v1.13.1
- v1.13.0
- v1.12.12
- v1.12.11
- v1.12.10
- v1.12.9
- v1.12.8
- v1.12.7
- v1.12.6
- v1.12.5
- v1.12.4
- v1.12.3
- v1.12.2
- v1.12.1
- v1.12.0
- v1.11.0
- v1.10.1
- v1.10.0
- v1.9.1
- v1.9.0
- v1.8.1
- v1.8.0
- v1.7.4
- v1.7.3
- v1.7.2
- v1.7.1
- v1.7.0
- v1.6.0
- v1.5.0
- v1.4.1
- v1.4.0
- v1.3.0
- v1.2.9
- v1.2.8
- v1.2.7
- v1.2.6
- v1.2.5
- v1.2.4
- v1.2.3
- v1.2.2
- v1.2.1
- v1.2.0
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.2
- v1.0.1
- v1.0.0
- v0.2.1
- v0.2.0
- v0.1.0
- dev-proposal_1
- dev-proposal_2
This package is auto-updated.
Last update: 2024-12-12 23:19:03 UTC
README
Idiomatic PHP client for Translation.
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 Using the Handwritten Client (Interacts with the V2 API)
require 'vendor/autoload.php'; use Google\Cloud\Translate\V2\TranslateClient; $translate = new TranslateClient([ 'key' => 'your_key' ]); // Translate text from english to french. $result = $translate->translate('Hello world!', [ 'target' => 'fr' ]); echo $result['text'] . "\n"; // Detect the language of a string. $result = $translate->detectLanguage('Greetings from Michigan!'); echo $result['languageCode'] . "\n"; // Get the languages supported for translation specifically for your target language. $languages = $translate->localizedLanguages([ 'target' => 'en' ]); foreach ($languages as $language) { echo $language['name'] . "\n"; echo $language['code'] . "\n"; } // Get all languages supported for translation. $languages = $translate->languages(); foreach ($languages as $language) { echo $language . "\n"; }
Sample Using the Generated Client (Interacts with the V3 API)
require 'vendor/autoload.php'; use Google\Cloud\Translate\V3\TranslationServiceClient; $translationClient = new TranslationServiceClient(); $content = ['one', 'two', 'three']; $targetLanguage = 'es'; $response = $translationClient->translateText( $content, $targetLanguage, TranslationServiceClient::locationName('[PROJECT_ID]', 'global') ); foreach ($response->getTranslations() as $key => $translation) { $separator = $key === 2 ? '!' : ', '; echo $translation->getTranslatedText() . $separator; }
Choosing the Right Client for You
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.
Next Steps
- Understand the official documentation.
- Take a look at in-depth usage samples.