use of software.amazon.awssdk.services.translate.model.StartTextTranslationJobRequest 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 "";
}
Aggregations