Search in sources :

Example 6 with TranslateException

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

the class ListTextTranslationJobs method getTranslationJobs.

// snippet-start:[translate.java2._list_jobs.main]
public static void getTranslationJobs(TranslateClient translateClient) {
    try {
        ListTextTranslationJobsRequest textTranslationJobsRequest = ListTextTranslationJobsRequest.builder().maxResults(10).build();
        ListTextTranslationJobsResponse jobsResponse = translateClient.listTextTranslationJobs(textTranslationJobsRequest);
        List<TextTranslationJobProperties> props = jobsResponse.textTranslationJobPropertiesList();
        for (TextTranslationJobProperties prop : props) {
            System.out.println("The job name is: " + prop.jobName());
            System.out.println("The job id is: " + prop.jobId());
        }
    } catch (TranslateException e) {
        System.err.println(e.getMessage());
        System.exit(1);
    }
}
Also used : TextTranslationJobProperties(software.amazon.awssdk.services.translate.model.TextTranslationJobProperties) ListTextTranslationJobsResponse(software.amazon.awssdk.services.translate.model.ListTextTranslationJobsResponse) ListTextTranslationJobsRequest(software.amazon.awssdk.services.translate.model.ListTextTranslationJobsRequest) TranslateException(software.amazon.awssdk.services.translate.model.TranslateException)

Example 7 with TranslateException

use of software.amazon.awssdk.services.translate.model.TranslateException 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 8 with TranslateException

use of software.amazon.awssdk.services.translate.model.TranslateException 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

TranslateException (software.amazon.awssdk.services.translate.model.TranslateException)8 TranslateTextRequest (software.amazon.awssdk.services.translate.model.TranslateTextRequest)5 TranslateTextResponse (software.amazon.awssdk.services.translate.model.TranslateTextResponse)5 Region (software.amazon.awssdk.regions.Region)4 TranslateClient (software.amazon.awssdk.services.translate.TranslateClient)4 DescribeTextTranslationJobRequest (software.amazon.awssdk.services.translate.model.DescribeTextTranslationJobRequest)2 DescribeTextTranslationJobResponse (software.amazon.awssdk.services.translate.model.DescribeTextTranslationJobResponse)2 InputDataConfig (software.amazon.awssdk.services.translate.model.InputDataConfig)1 ListTextTranslationJobsRequest (software.amazon.awssdk.services.translate.model.ListTextTranslationJobsRequest)1 ListTextTranslationJobsResponse (software.amazon.awssdk.services.translate.model.ListTextTranslationJobsResponse)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 TextTranslationJobProperties (software.amazon.awssdk.services.translate.model.TextTranslationJobProperties)1