Swift Examples - DeepL

Service setup

Create a DeepL service in the AIProxy dashboard

Follow the integration guide, selecting the DeepL icon on the 'Create a New Service' form.

How to create translations using DeepL

import AIProxy

let service = AIProxy.deepLService(
    partialKey: "partial-key-from-your-developer-dashboard",
    serviceURL: "service-url-from-your-developer-dashboard"
)

do {
    let body = DeepLTranslateRequestBody(targetLang: "ES", text: ["hello world"])
    let response = try await service.translateRequest(body: body)
    // Do something with `response.translations`
}  catch AIProxyError.unsuccessfulRequest(let statusCode, let responseBody) {
    print("Received \(statusCode) status code with response body: \(responseBody)")
} catch {
    print("Could not create DeepL translation: \(error.localizedDescription)")
}