Search in sources :

Example 6 with TranslateClient

use of software.amazon.awssdk.services.translate.TranslateClient in project aws-doc-sdk-examples by awsdocs.

the class BatchTranslation method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "    <s3Uri> <s3UriOut> <jobName> <dataAccessRoleArn> \n\n" + "Where:\n" + "    s3Uri - the URI of the Amazon S3 bucket where the documents to translate are located. \n" + "    s3UriOut - the URI of the Amazon S3 bucket where the translated documents are saved to.  \n" + "    jobName - the job name. \n" + "    dataAccessRoleArn - the Amazon Resource Name (ARN) value of the role required for translation jobs.\n";
    if (args.length != 4) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String s3Uri = args[0];
    String s3UriOut = args[1];
    String jobName = args[2];
    String dataAccessRoleArn = args[3];
    Region region = Region.US_WEST_2;
    TranslateClient translateClient = TranslateClient.builder().region(region).build();
    String id = translateDocuments(translateClient, s3Uri, s3UriOut, jobName, dataAccessRoleArn);
    System.out.println("Translation job " + id + " is completed");
    translateClient.close();
}
Also used : TranslateClient(software.amazon.awssdk.services.translate.TranslateClient) Region(software.amazon.awssdk.regions.Region)

Example 7 with TranslateClient

use of software.amazon.awssdk.services.translate.TranslateClient in project aws-doc-sdk-examples by awsdocs.

the class ListTextTranslationJobs method main.

public static void main(String[] args) {
    Region region = Region.US_WEST_2;
    TranslateClient translateClient = TranslateClient.builder().region(region).build();
    getTranslationJobs(translateClient);
    translateClient.close();
}
Also used : TranslateClient(software.amazon.awssdk.services.translate.TranslateClient) Region(software.amazon.awssdk.regions.Region)

Example 8 with TranslateClient

use of software.amazon.awssdk.services.translate.TranslateClient in project aws-doc-sdk-examples by awsdocs.

the class LexService method textTranslateToEn.

public String textTranslateToEn(String lanCode, String text) {
    Region region = Region.US_EAST_1;
    TranslateClient translateClient = TranslateClient.builder().credentialsProvider(EnvironmentVariableCredentialsProvider.create()).region(region).build();
    try {
        TranslateTextRequest textRequest = TranslateTextRequest.builder().sourceLanguageCode(lanCode).targetLanguageCode("en").text(text).build();
        TranslateTextResponse textResponse = translateClient.translateText(textRequest);
        return textResponse.translatedText();
    } catch (TranslateException e) {
        System.err.println(e.getMessage());
        System.exit(1);
    }
    return "";
}
Also used : TranslateClient(software.amazon.awssdk.services.translate.TranslateClient) TranslateException(software.amazon.awssdk.services.translate.model.TranslateException) TranslateTextRequest(software.amazon.awssdk.services.translate.model.TranslateTextRequest) Region(software.amazon.awssdk.regions.Region) TranslateTextResponse(software.amazon.awssdk.services.translate.model.TranslateTextResponse)

Example 9 with TranslateClient

use of software.amazon.awssdk.services.translate.TranslateClient in project aws-doc-sdk-examples by awsdocs.

the class LexService method textTranslateFromEn.

public String textTranslateFromEn(String lanCode, String text) {
    Region region = Region.US_EAST_1;
    TranslateClient translateClient = TranslateClient.builder().credentialsProvider(EnvironmentVariableCredentialsProvider.create()).region(region).build();
    try {
        TranslateTextRequest textRequest = TranslateTextRequest.builder().sourceLanguageCode("en").targetLanguageCode(lanCode).text(text).build();
        TranslateTextResponse textResponse = translateClient.translateText(textRequest);
        return textResponse.translatedText();
    } catch (TranslateException e) {
        System.err.println(e.getMessage());
        System.exit(1);
    }
    return "";
}
Also used : TranslateClient(software.amazon.awssdk.services.translate.TranslateClient) TranslateException(software.amazon.awssdk.services.translate.model.TranslateException) TranslateTextRequest(software.amazon.awssdk.services.translate.model.TranslateTextRequest) Region(software.amazon.awssdk.regions.Region) TranslateTextResponse(software.amazon.awssdk.services.translate.model.TranslateTextResponse)

Aggregations

Region (software.amazon.awssdk.regions.Region)9 TranslateClient (software.amazon.awssdk.services.translate.TranslateClient)9 TranslateTextRequest (software.amazon.awssdk.services.translate.model.TranslateTextRequest)5 TranslateTextResponse (software.amazon.awssdk.services.translate.model.TranslateTextResponse)5 TranslateException (software.amazon.awssdk.services.translate.model.TranslateException)4 SnsClient (software.amazon.awssdk.services.sns.SnsClient)1