Chilkat  HOME  Android™  Classic ASP  C  C++  C#  Mono C#  .NET Core C#  C# UWP/WinRT  DataFlex  Delphi ActiveX  Delphi DLL  Visual FoxPro  Java  Lianja  MFC  Objective-C  Perl  PHP ActiveX  PHP Extension  PowerBuilder  PowerShell  PureBasic  CkPython  Chilkat2-Python  Ruby  SQL Server  Swift 2  Swift 3,4,5...  Tcl  Unicode C  Unicode C++  Visual Basic 6.0  VB.NET  VB.NET UWP/WinRT  VBScript  Xojo Plugin  Node.js  Excel  Go
 
      (Excel) Amazon Translate TextDemonstrates how to use the AWS Translate service to translate text from one language to another. 
 ' This example requires the Chilkat API to have been previously unlocked. ' See Global Unlock Sample for sample code. Dim rest As Chilkat.Rest Set rest = Chilkat.NewRest Dim authAws As Chilkat.AuthAws Set authAws = Chilkat.NewAuthAws authAws.AccessKey = "AWS_ACCESS_KEY" authAws.SecretKey = "AWS_SECRET_KEY" authAws.Region = "us-west-2" authAws.ServiceName = "translate" success = rest.SetAuthAws(authAws) ' URL: https://translate.us-west-2.amazonaws.com/ bTls = True port = 443 bAutoReconnect = True success = rest.Connect("translate.us-west-2.amazonaws.com",port,bTls,bAutoReconnect) If (success <> True) Then Debug.Print "ConnectFailReason: "; rest.ConnectFailReason Debug.Print rest.LastErrorText Exit Sub End If ' Translate text from English to German Dim json As Chilkat.JsonObject Set json = Chilkat.NewJsonObject success = json.UpdateString("SourceLanguageCode","en") success = json.UpdateString("TargetLanguageCode","de") success = json.UpdateString("Text","This is the text to be translated") success = rest.AddHeader("Content-Type","application/x-amz-json-1.1") success = rest.AddHeader("X-Amz-Target","AWSShineFrontendService_20170701.TranslateText") Dim sbRequestBody As Chilkat.StringBuilder Set sbRequestBody = Chilkat.NewStringBuilder success = json.EmitSb(sbRequestBody) Dim sbResponseBody As Chilkat.StringBuilder Set sbResponseBody = Chilkat.NewStringBuilder success = rest.FullRequestSb("POST","/",sbRequestBody,sbResponseBody) If (success <> True) Then Debug.Print rest.LastErrorText Exit Sub End If respStatusCode = rest.ResponseStatusCode If (respStatusCode >= 400) Then Debug.Print "Response Status Code = "; respStatusCode Debug.Print "Response Header:" Debug.Print rest.ResponseHeader Debug.Print "Response Body:" Debug.Print sbResponseBody.GetAsString() Exit Sub End If Dim jsonResponse As Chilkat.JsonObject Set jsonResponse = Chilkat.NewJsonObject success = jsonResponse.LoadSb(sbResponseBody) jsonResponse.EmitCompact = False Debug.Print jsonResponse.Emit() ' { ' "SourceLanguageCode": "en", ' "TargetLanguageCode": "de", ' "TranslatedText": "Dies ist der zu bersetzende Text" ' } Debug.Print jsonResponse.StringOf("TranslatedText")  | 
  ||||
© 2000-2022 Chilkat Software, Inc. All Rights Reserved.