Amazon Translate
Developer Guide

The AWS Documentation website is getting a new look!
Try it now and let us know what you think. Switch to the new look >>

You can return to the original look by selecting English in the language selector above.

Translating Text Using the AWS SDK for Java

The following example demonstrates using the TranslateText operation in Java. To run this example, you need the AWS SDK for Java. For instructions for installing the SDK for Java, see Set up the AWS SDK for Java.

import com.amazonaws.auth.AWSStaticCredentialsProvider; import com.amazonaws.auth.BasicAWSCredentials; import com.amazonaws.client.builder.AwsClientBuilder; import; import; import; import; public class App { private static final String REGION = "region"; public static void main( String[] args ) { // Create credentials using a provider chain. For more information, see // AWSCredentialsProvider awsCreds = DefaultAWSCredentialsProviderChain.getInstance(); AmazonTranslate translate = AmazonTranslateClient.builder() .withCredentials(new AWSStaticCredentialsProvider(awsCreds.getCredentials())) .withRegion(REGION) .build(); TranslateTextRequest request = new TranslateTextRequest() .withText("Hello, world") .withSourceLanguageCode("en") .withTargetLanguageCode("es"); TranslateTextResult result = translate.translateText(request); System.out.println(result.getTranslatedText()); } }

You can change the source and target languages as long as the language pair selected is supported by Amazon Translate in the correct combination. For more information, see Supported Languages and Language Codes