開始使用 Amazon Translate 任務 AWS SDK - Amazon Translate

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

開始使用 Amazon Translate 任務 AWS SDK

以下程式碼範例顯示做法:

  • 啟動非同步批次翻譯工作。

  • 等待非同步工作完成。

  • 描述非同步工作。

SAP ABAP
SDK對於 SAP ABAP
注意

還有更多關於 GitHub。尋找完整的範例,並瞭解如何設定和執行 AWS 代碼示例存儲庫

DATA lo_inputdataconfig TYPE REF TO /aws1/cl_xl8inputdataconfig. DATA lo_outputdataconfig TYPE REF TO /aws1/cl_xl8outputdataconfig. DATA lt_targetlanguagecodes TYPE /aws1/cl_xl8tgtlanguagecodes00=>tt_targetlanguagecodestrlist. DATA lo_targetlanguagecodes TYPE REF TO /aws1/cl_xl8tgtlanguagecodes00. "Create an ABAP object for the input data config." CREATE OBJECT lo_inputdataconfig EXPORTING iv_s3uri = iv_input_data_s3uri iv_contenttype = iv_input_data_contenttype. "Create an ABAP object for the output data config." CREATE OBJECT lo_outputdataconfig EXPORTING iv_s3uri = iv_output_data_s3uri. "Create an internal table for target languages." CREATE OBJECT lo_targetlanguagecodes EXPORTING iv_value = iv_targetlanguagecode. INSERT lo_targetlanguagecodes INTO TABLE lt_targetlanguagecodes. TRY. DATA(lo_translationjob_result) = lo_xl8->starttexttranslationjob( EXPORTING io_inputdataconfig = lo_inputdataconfig io_outputdataconfig = lo_outputdataconfig it_targetlanguagecodes = lt_targetlanguagecodes iv_dataaccessrolearn = iv_dataaccessrolearn iv_jobname = iv_jobname iv_sourcelanguagecode = iv_sourcelanguagecode ). MESSAGE 'Translation job started.' TYPE 'I'. CATCH /aws1/cx_xl8internalserverex . MESSAGE 'An internal server error occurred. Retry your request.' TYPE 'E'. CATCH /aws1/cx_xl8invparamvalueex . MESSAGE 'The value of the parameter is not valid.' TYPE 'E'. CATCH /aws1/cx_xl8invalidrequestex. MESSAGE 'The request that you made is not valid.' TYPE 'E'. CATCH /aws1/cx_xl8resourcenotfoundex . MESSAGE 'The resource you are looking for has not been found.' TYPE 'E'. CATCH /aws1/cx_xl8toomanyrequestsex. MESSAGE 'You have made too many requests within a short period of time. ' TYPE 'E'. CATCH /aws1/cx_xl8unsuppedlanguage00 . MESSAGE 'Amazon Translate does not support translation from the language of the source text into the requested target language.' TYPE 'E'. ENDTRY. "Get the job ID." DATA(lv_jobid) = lo_translationjob_result->get_jobid( ). "Wait for translate job to complete." DATA(lo_des_translation_result) = lo_xl8->describetexttranslationjob( iv_jobid = lv_jobid ). WHILE lo_des_translation_result->get_textxlationjobproperties( )->get_jobstatus( ) <> 'COMPLETED'. IF sy-index = 30. EXIT. "Maximum 900 seconds." ENDIF. WAIT UP TO 30 SECONDS. lo_des_translation_result = lo_xl8->describetexttranslationjob( iv_jobid = lv_jobid ). ENDWHILE. TRY. oo_result = lo_xl8->describetexttranslationjob( "oo_result is returned for testing purposes." EXPORTING iv_jobid = lv_jobid ). MESSAGE 'Job description retrieved.' TYPE 'I'. CATCH /aws1/cx_xl8internalserverex . MESSAGE 'An internal server error occurred. Retry your request.' TYPE 'E'. CATCH /aws1/cx_xl8resourcenotfoundex . MESSAGE 'The resource you are looking for has not been found.' TYPE 'E'. CATCH /aws1/cx_xl8toomanyrequestsex. MESSAGE 'You have made too many requests within a short period of time.' TYPE 'E'. ENDTRY.

有關的完整列表 AWS SDK開發人員指南和代碼示例,請參閱使用此服務 AWS SDK。本主題也包含有關入門的資訊以及舊SDK版的詳細資訊。