TranslateTextAWS SDKOR와 함께 사용 CLI - AWS SDK코드 예제

AWS 문서 AWS SDK SDK 예제 GitHub 리포지토리에 더 많은 예제가 있습니다.

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

TranslateTextAWS SDKOR와 함께 사용 CLI

다음 코드 예제는 TranslateText의 사용 방법을 보여 줍니다.

.NET
AWS SDK for .NET
참고

더 많은 정보가 있습니다 GitHub. AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

using System; using System.IO; using System.Threading.Tasks; using Amazon.S3; using Amazon.S3.Transfer; using Amazon.Translate; using Amazon.Translate.Model; /// <summary> /// Take text from a file stored a Amazon Simple Storage Service (Amazon S3) /// object and translate it using the Amazon Transfer Service. /// </summary> public class TranslateText { public static async Task Main() { // If the region you want to use is different from the region // defined for the default user, supply it as a parameter to the // Amazon Translate client object constructor. var client = new AmazonTranslateClient(); // Set the source language to "auto" to request Amazon Translate to // automatically detect te language of the source text. // You can get a list of the languages supposed by Amazon Translate // in the Amazon Translate Developer's Guide here: // https://docs.aws.amazon.com/translate/latest/dg/what-is.html string srcLang = "en"; // English. string destLang = "fr"; // French. // The Amazon Simple Storage Service (Amazon S3) bucket where the // source text file is stored. string srcBucket = "DOC-EXAMPLE-BUCKET"; string srcTextFile = "source.txt"; var srcText = await GetSourceTextAsync(srcBucket, srcTextFile); var destText = await TranslatingTextAsync(client, srcLang, destLang, srcText); ShowText(srcText, destText); } /// <summary> /// Use the Amazon S3 TransferUtility to retrieve the text to translate /// from an object in an S3 bucket. /// </summary> /// <param name="srcBucket">The name of the S3 bucket where the /// text is stored. /// </param> /// <param name="srcTextFile">The key of the S3 object that /// contains the text to translate.</param> /// <returns>A string representing the source text.</returns> public static async Task<string> GetSourceTextAsync(string srcBucket, string srcTextFile) { string srcText = string.Empty; var s3Client = new AmazonS3Client(); TransferUtility utility = new TransferUtility(s3Client); using var stream = await utility.OpenStreamAsync(srcBucket, srcTextFile); StreamReader file = new System.IO.StreamReader(stream); srcText = file.ReadToEnd(); return srcText; } /// <summary> /// Use the Amazon Translate Service to translate the document from the /// source language to the specified destination language. /// </summary> /// <param name="client">The Amazon Translate Service client used to /// perform the translation.</param> /// <param name="srcLang">The language of the source text.</param> /// <param name="destLang">The destination language for the translated /// text.</param> /// <param name="text">A string representing the text to ranslate.</param> /// <returns>The text that has been translated to the destination /// language.</returns> public static async Task<string> TranslatingTextAsync(AmazonTranslateClient client, string srcLang, string destLang, string text) { var request = new TranslateTextRequest { SourceLanguageCode = srcLang, TargetLanguageCode = destLang, Text = text, }; var response = await client.TranslateTextAsync(request); return response.TranslatedText; } /// <summary> /// Show the original text followed by the translated text. /// </summary> /// <param name="srcText">The original text to be translated.</param> /// <param name="destText">The translated text.</param> public static void ShowText(string srcText, string destText) { Console.WriteLine("Source text:"); Console.WriteLine(srcText); Console.WriteLine(); Console.WriteLine("Translated text:"); Console.WriteLine(destText); } }
PowerShell
에 대한 도구 PowerShell

예 1: 지정된 영어 텍스트를 프랑스어로 변환합니다. 변환할 텍스트를 -Text 매개 변수로 전달할 수도 있습니다.

"Hello World" | ConvertTo-TRNTargetLanguage -SourceLanguageCode en -TargetLanguageCode fr
  • 자세한 API 내용은 AWS Tools for PowerShell Cmdlet 참조를 참조하십시오 TranslateText.

SAP ABAP
SDK에 대한 SAP ABAP
참고

더 많은 정보가 있습니다 GitHub. AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

"Translates input text from the source language to the target language." TRY. oo_result = lo_xl8->translatetext( "oo_result is returned for testing purposes." EXPORTING iv_text = iv_text iv_sourcelanguagecode = iv_sourcelanguagecode iv_targetlanguagecode = iv_targetlanguagecode ). MESSAGE 'Translation completed.' TYPE 'I'. CATCH /aws1/cx_xl8detectedlanguage00 . MESSAGE 'The confidence that Amazon Comprehend accurately detected the source language is low.' TYPE 'E'. CATCH /aws1/cx_xl8internalserverex . MESSAGE 'An internal server error occurred.' 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_xl8serviceunavailex . MESSAGE 'The Amazon Translate service is temporarily unavailable.' TYPE 'E'. CATCH /aws1/cx_xl8textsizelmtexcdex . MESSAGE 'The size of the text you submitted exceeds the size limit. ' 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.
  • 자세한 API 내용은 SAPABAPAPI참조를AWS SDK 위해 TranslateTextin을 참조하십시오.