Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

Swift 3,4,5... Web API Examples

Primary Categories

ABN AMRO
AWS Secrets Manager
AWS Security Token Service
AWS Translate
Activix CRM
Adyen
Alibaba Cloud OSS
Amazon Cognito
Amazon DynamoDB
Amazon MWS
Amazon Pay
Amazon Rekognition
Amazon SP-API
Amazon Voice ID
Aruba Fatturazione
Azure Maps
Azure Monitor
Azure OAuth2
Azure Storage Accounts
Backblaze S3
Banco Inter
Belgian eHealth Platform
Bitfinex v2 REST
Bluzone
BrickLink
Bunny CDN
CallRail
CardConnect
Cerved
ClickBank
Clickatell
Cloudfare
Constant Contact
DocuSign
Duo Auth MFA
ETrade
Ecwid
Egypt ITIDA
Egypt eReceipt
Etsy
Facebook
Faire
Frame.io
GeoOp
GetHarvest
Global Payments
Google People
Google Search Console
Google Translate
Google Vision
Hungary NAV Invoicing
IBM Text to Speech
Ibanity
IntakeQ
JCC Cyprus
Jira
Lightspeed
MYOB
Magento
Mailgun
Malaysia MyInvois

Mastercard
MedTunnel
MercadoLibre
MessageMedia
Microsoft Calendar
Microsoft Group
Microsoft Tasks and Plans
Microsoft Teams
Moody's
Okta OAuth/OIDC
OneLogin OIDC
OneNote
OpenAI ChatGPT
PRODA
PayPal
Paynow.pl
Peoplevox
Populi
QuickBooks
Rabobank
Refinitiv
Royal Mail OBA
SCiS Schools Catalogue
SII Chile
SMSAPI
SOAP finkok.com
Salesforce
SendGrid
Shippo
Shopify
Shopware
Shopware 6
SimpleTexting
Square
Stripe
SugarCRM
TicketBAI
TikTok Shop
Trello
Twilio
Twitter API v2
Twitter v1
UPS
UniPin
VoiceBase
Vonage
WaTrend
Walmart v3
Wasabi
WhatsApp
WiX
WooCommerce
WordPress
Xero
Yahoo Mail
Yapily
Yousign
ZATCA
Zendesk
Zoom
_Miscellaneous_
eBay
effectconnect
hacienda.go.cr

 

 

 

(Swift 3,4,5...) Amazon Translate Text

Demonstrates how to use the AWS Translate service to translate text from one language to another.

Chilkat Downloads for the Swift Programming Language

MAC OS X (Cocoa) Objective-C/Swift Libs

iOS Objective-C/Swift Libs

func chilkatTest() {
    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    let rest = CkoRest()!
    var success: Bool

    let authAws = CkoAuthAws()!
    authAws.accessKey = "AWS_ACCESS_KEY"
    authAws.secretKey = "AWS_SECRET_KEY"
    authAws.region = "us-west-2"
    authAws.serviceName = "translate"
    rest.setAuthAws(authAws)

    // URL: https://translate.us-west-2.amazonaws.com/
    var bTls: Bool = true
    var port: Int = 443
    var bAutoReconnect: Bool = true
    success = rest.connect("translate.us-west-2.amazonaws.com", port: port, tls: bTls, autoReconnect: bAutoReconnect)
    if success != true {
        print("ConnectFailReason: \(rest.connectFailReason.intValue)")
        print("\(rest.lastErrorText!)")
        return
    }

    // Translate text from English to German
    let json = CkoJsonObject()!
    json.update("SourceLanguageCode", value: "en")
    json.update("TargetLanguageCode", value: "de")
    json.update("Text", value: "This is the text to be translated")

    rest.addHeader("Content-Type", value: "application/x-amz-json-1.1")
    rest.addHeader("X-Amz-Target", value: "AWSShineFrontendService_20170701.TranslateText")

    let sbRequestBody = CkoStringBuilder()!
    json.emitSb(sbRequestBody)
    let sbResponseBody = CkoStringBuilder()!
    success = rest.fullRequestSb("POST", uriPath: "/", requestBody: sbRequestBody, responseBody: sbResponseBody)
    if success != true {
        print("\(rest.lastErrorText!)")
        return
    }

    var respStatusCode: Int = rest.responseStatusCode.intValue
    if respStatusCode >= 400 {
        print("Response Status Code = \(respStatusCode)")
        print("Response Header:")
        print("\(rest.responseHeader!)")
        print("Response Body:")
        print("\(sbResponseBody.getAsString()!)")
        return
    }

    let jsonResponse = CkoJsonObject()!
    jsonResponse.loadSb(sbResponseBody)
    jsonResponse.emitCompact = false

    print("\(jsonResponse.emit()!)")

    // {
    //   "SourceLanguageCode": "en",
    //   "TargetLanguageCode": "de",
    //   "TranslatedText": "Dies ist der zu bersetzende Text"
    // }

    print("\(jsonResponse.string(of: "TranslatedText")!)")

}

 

© 2000-2024 Chilkat Software, Inc. All Rights Reserved.