Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(DataFlex) Amazon Translate TextDemonstrates how to use the AWS Translate service to translate text from one language to another.
Use ChilkatAx-win32.pkg Procedure Test Handle hoRest Boolean iSuccess Variant vAuthAws Handle hoAuthAws Boolean iBTls Integer iPort Boolean iBAutoReconnect Handle hoJson Variant vSbRequestBody Handle hoSbRequestBody Variant vSbResponseBody Handle hoSbResponseBody Integer iRespStatusCode Handle hoJsonResponse String sTemp1 Integer iTemp1 // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. Get Create (RefClass(cComChilkatRest)) To hoRest If (Not(IsComObjectCreated(hoRest))) Begin Send CreateComObject of hoRest End Get Create (RefClass(cComChilkatAuthAws)) To hoAuthAws If (Not(IsComObjectCreated(hoAuthAws))) Begin Send CreateComObject of hoAuthAws End Set ComAccessKey Of hoAuthAws To "AWS_ACCESS_KEY" Set ComSecretKey Of hoAuthAws To "AWS_SECRET_KEY" Set ComRegion Of hoAuthAws To "us-west-2" Set ComServiceName Of hoAuthAws To "translate" Get pvComObject of hoAuthAws to vAuthAws Get ComSetAuthAws Of hoRest vAuthAws To iSuccess // URL: https://translate.us-west-2.amazonaws.com/ Move True To iBTls Move 443 To iPort Move True To iBAutoReconnect Get ComConnect Of hoRest "translate.us-west-2.amazonaws.com" iPort iBTls iBAutoReconnect To iSuccess If (iSuccess <> True) Begin Get ComConnectFailReason Of hoRest To iTemp1 Showln "ConnectFailReason: " iTemp1 Get ComLastErrorText Of hoRest To sTemp1 Showln sTemp1 Procedure_Return End // Translate text from English to German Get Create (RefClass(cComChilkatJsonObject)) To hoJson If (Not(IsComObjectCreated(hoJson))) Begin Send CreateComObject of hoJson End Get ComUpdateString Of hoJson "SourceLanguageCode" "en" To iSuccess Get ComUpdateString Of hoJson "TargetLanguageCode" "de" To iSuccess Get ComUpdateString Of hoJson "Text" "This is the text to be translated" To iSuccess Get ComAddHeader Of hoRest "Content-Type" "application/x-amz-json-1.1" To iSuccess Get ComAddHeader Of hoRest "X-Amz-Target" "AWSShineFrontendService_20170701.TranslateText" To iSuccess Get Create (RefClass(cComChilkatStringBuilder)) To hoSbRequestBody If (Not(IsComObjectCreated(hoSbRequestBody))) Begin Send CreateComObject of hoSbRequestBody End Get pvComObject of hoSbRequestBody to vSbRequestBody Get ComEmitSb Of hoJson vSbRequestBody To iSuccess Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody If (Not(IsComObjectCreated(hoSbResponseBody))) Begin Send CreateComObject of hoSbResponseBody End Get pvComObject of hoSbRequestBody to vSbRequestBody Get pvComObject of hoSbResponseBody to vSbResponseBody Get ComFullRequestSb Of hoRest "POST" "/" vSbRequestBody vSbResponseBody To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoRest To sTemp1 Showln sTemp1 Procedure_Return End Get ComResponseStatusCode Of hoRest To iRespStatusCode If (iRespStatusCode >= 400) Begin Showln "Response Status Code = " iRespStatusCode Showln "Response Header:" Get ComResponseHeader Of hoRest To sTemp1 Showln sTemp1 Showln "Response Body:" Get ComGetAsString Of hoSbResponseBody To sTemp1 Showln sTemp1 Procedure_Return End Get Create (RefClass(cComChilkatJsonObject)) To hoJsonResponse If (Not(IsComObjectCreated(hoJsonResponse))) Begin Send CreateComObject of hoJsonResponse End Get pvComObject of hoSbResponseBody to vSbResponseBody Get ComLoadSb Of hoJsonResponse vSbResponseBody To iSuccess Set ComEmitCompact Of hoJsonResponse To False Get ComEmit Of hoJsonResponse To sTemp1 Showln sTemp1 // { // "SourceLanguageCode": "en", // "TargetLanguageCode": "de", // "TranslatedText": "Dies ist der zu �bersetzende Text" // } Get ComStringOf Of hoJsonResponse "TranslatedText" To sTemp1 Showln sTemp1 End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.