Search in sources :

Example 1 with InputDataConfig

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

the class BatchTranslation method translateDocuments.

// snippet-start:[translate.java2._batch.main]
public static String translateDocuments(TranslateClient translateClient, String s3Uri, String s3UriOut, String jobName, String dataAccessRoleArn) {
    try {
        InputDataConfig dataConfig = InputDataConfig.builder().s3Uri(s3Uri).contentType("text/plain").build();
        OutputDataConfig outputDataConfig = OutputDataConfig.builder().s3Uri(s3UriOut).build();
        StartTextTranslationJobRequest textTranslationJobRequest = StartTextTranslationJobRequest.builder().jobName(jobName).dataAccessRoleArn(dataAccessRoleArn).inputDataConfig(dataConfig).outputDataConfig(outputDataConfig).sourceLanguageCode("en").targetLanguageCodes("fr").build();
        StartTextTranslationJobResponse textTranslationJobResponse = translateClient.startTextTranslationJob(textTranslationJobRequest);
        // Keep checking until job is done
        boolean jobDone = false;
        String jobStatus = "";
        String jobId = textTranslationJobResponse.jobId();
        DescribeTextTranslationJobRequest jobRequest = DescribeTextTranslationJobRequest.builder().jobId(jobId).build();
        while (!jobDone) {
            // Check status on each loop
            DescribeTextTranslationJobResponse response = translateClient.describeTextTranslationJob(jobRequest);
            jobStatus = response.textTranslationJobProperties().jobStatusAsString();
            System.out.println(jobStatus);
            if (jobStatus.contains("COMPLETED"))
                jobDone = true;
            else {
                System.out.print(".");
                Thread.sleep(sleepTime * 1000);
            }
        }
        return textTranslationJobResponse.jobId();
    } catch (TranslateException | InterruptedException e) {
        System.err.println(e.getMessage());
        System.exit(1);
    }
    return "";
}
Also used : StartTextTranslationJobResponse(software.amazon.awssdk.services.translate.model.StartTextTranslationJobResponse) DescribeTextTranslationJobRequest(software.amazon.awssdk.services.translate.model.DescribeTextTranslationJobRequest) OutputDataConfig(software.amazon.awssdk.services.translate.model.OutputDataConfig) TranslateException(software.amazon.awssdk.services.translate.model.TranslateException) DescribeTextTranslationJobResponse(software.amazon.awssdk.services.translate.model.DescribeTextTranslationJobResponse) InputDataConfig(software.amazon.awssdk.services.translate.model.InputDataConfig) StartTextTranslationJobRequest(software.amazon.awssdk.services.translate.model.StartTextTranslationJobRequest)

Aggregations

DescribeTextTranslationJobRequest (software.amazon.awssdk.services.translate.model.DescribeTextTranslationJobRequest)1 DescribeTextTranslationJobResponse (software.amazon.awssdk.services.translate.model.DescribeTextTranslationJobResponse)1 InputDataConfig (software.amazon.awssdk.services.translate.model.InputDataConfig)1 OutputDataConfig (software.amazon.awssdk.services.translate.model.OutputDataConfig)1 StartTextTranslationJobRequest (software.amazon.awssdk.services.translate.model.StartTextTranslationJobRequest)1 StartTextTranslationJobResponse (software.amazon.awssdk.services.translate.model.StartTextTranslationJobResponse)1 TranslateException (software.amazon.awssdk.services.translate.model.TranslateException)1