Translate client

This page contains examples with the Translate client. See the client introduction for a more detailed description how to use a client. You may also want to consider the authentication documentation to understand the many ways you can authenticate with AWS.

The Translate package could be installed with Composer.

composer require async-aws/translate

A new client object may be instantiated by:

use AsyncAws\Translate\TranslateClient; $translate = new TranslateClient();

The authentication parameters is read from the environment by default. You can also specify a AWS access id and secret:

use AsyncAws\Translate\TranslateClient; $translate = new TranslateClient([ 'accessKeyId' => 'my_access_key', 'accessKeySecret' => 'my_access_secret', 'region' => 'eu-central-1', ]);

For all available options, see the configuration reference.

Usage

Write records

use AsyncAws\Translate\TranslateClient; use AsyncAws\Translate\ValueObject\TranslationSettings; $translate = new TranslateClient(); $result = $translate->translateText([ 'Text' => 'Jag gillar glass', 'SourceLanguageCode' => 'sv', // 'auto' 'TargetLanguageCode' => 'en', 'Settings' => new TranslationSettings([ 'Formality' => 'INFORMAL', // FORMAL // 'Profanity' => 'MASK', ]), ]); echo $result->getTranslatedText(); // "I like ice cream"

The source code to this page is found on GitHub.