- AWS Code Sample

TranslateText demonstrates how to use the translatetext operation.

/** * Copyright 2010-2019, Inc. or its affiliates. All Rights Reserved. * * This file is licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. A copy of * the License is located at * * * * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. */ 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(); AWSTranslate translate = AmazonTranslateClient.standard() .withCredentials(new AWSStaticCredentialsProvider(awsCreds)) .withRegion(REGION) .build(); TranslateTextRequest request = new TranslateTextRequest() .withText("Hello, world") .withSourceLanguageCode("en") .withTargetLanguageCode("es"); TranslateTextResult result = translate.translateText(request); System.out.println(result.getTranslatedText()); } }

Sample Details

Service: translate

Last tested: 2019-01-31

Author: AWS

Type: full-example