DeepL 🌍

World’s most accurate AI translation.

🗣️

What you can do: Translate text and documents between 30+ languages with superior quality, preserve formatting, detect source language automatically, and handle specialized terminology.

Setup

Add your DeepL API key in the ProtectMyAPI Dashboard.


Text Translation

Basic Translation

let deepl = ProtectMyAPI.deepLService()
 
let result = try await deepl.translateText(
    text: "Hello, how are you?",
    targetLang: "DE" // German
)
 
print("Translation: \(result.translations.first?.text ?? "")")
print("Detected language: \(result.translations.first?.detectedSourceLanguage ?? "")")

With Source Language

let result = try await deepl.translateText(
    text: "Bonjour le monde",
    sourceLang: "FR", // French
    targetLang: "EN-US" // American English
)

Multiple Texts

let result = try await deepl.translateText(
    texts: [
        "Good morning",
        "How are you?",
        "See you later"
    ],
    targetLang: "ES" // Spanish
)
 
for translation in result.translations {
    print(translation.text)
}
// Buenos días
// ¿Cómo estás?
// Hasta luego

Advanced Options

Formality

Control formal vs informal tone:

// Formal translation (e.g., "Sie" in German)
let formal = try await deepl.translateText(
    text: "How are you?",
    targetLang: "DE",
    options: DeepLTranslateOptions(
        formality: .more // more, less, default, preferMore, preferLess
    )
)
// "Wie geht es Ihnen?"
 
// Informal translation (e.g., "du" in German)
let informal = try await deepl.translateText(
    text: "How are you?",
    targetLang: "DE",
    options: DeepLTranslateOptions(
        formality: .less
    )
)
// "Wie geht es dir?"

Preserve Formatting

let result = try await deepl.translateText(
    text: "Welcome to <b>our store</b>!",
    targetLang: "FR",
    options: DeepLTranslateOptions(
        preserveFormatting: true,
        tagHandling: .xml // Handle XML/HTML tags
    )
)
// "Bienvenue dans <b>notre magasin</b> !"

Glossary

Use custom terminology:

let result = try await deepl.translateText(
    text: "The API returns a response object",
    targetLang: "DE",
    options: DeepLTranslateOptions(
        glossaryId: "your-glossary-id" // Pre-created glossary
    )
)

Split Sentences

Control sentence splitting behavior:

let result = try await deepl.translateText(
    text: "Dr. Smith went to Washington. He arrived at noon.",
    targetLang: "DE",
    options: DeepLTranslateOptions(
        splitSentences: .nonewlines // off, on, nonewlines
    )
)

Document Translation

Translate entire documents (PDF, DOCX, PPTX, etc.):

// Upload document for translation
let document = try await deepl.translateDocument(
    fileURL: documentURL,
    targetLang: "FR",
    options: DeepLDocumentOptions(
        formality: .more
    )
)
 
print("Document ID: \(document.documentId)")
print("Key: \(document.documentKey)")
 
// Check translation status
let status = try await deepl.getDocumentStatus(
    documentId: document.documentId,
    documentKey: document.documentKey
)
 
print("Status: \(status.status)") // queued, translating, done, error
print("Progress: \(status.secondsRemaining ?? 0) seconds remaining")
 
// Download translated document
if status.status == "done" {
    let translatedData = try await deepl.downloadDocument(
        documentId: document.documentId,
        documentKey: document.documentKey
    )
    // Save translatedData to file
}

Supported Languages

Source Languages

CodeLanguage
BGBulgarian
CSCzech
DADanish
DEGerman
ELGreek
ENEnglish
ESSpanish
ETEstonian
FIFinnish
FRFrench
HUHungarian
IDIndonesian
ITItalian
JAJapanese
KOKorean
LTLithuanian
LVLatvian
NBNorwegian
NLDutch
PLPolish
PTPortuguese
RORomanian
RURussian
SKSlovak
SLSlovenian
SVSwedish
TRTurkish
UKUkrainian
ZHChinese

Target Languages (with variants)

CodeLanguage
EN-GBEnglish (British)
EN-USEnglish (American)
PT-BRPortuguese (Brazilian)
PT-PTPortuguese (European)
ZH-HANSChinese (Simplified)
ZH-HANTChinese (Traditional)

Get Supported Languages

// Get source languages
let sourceLanguages = try await deepl.getSourceLanguages()
for lang in sourceLanguages {
    print("\(lang.language): \(lang.name)")
}
 
// Get target languages
let targetLanguages = try await deepl.getTargetLanguages()
for lang in targetLanguages {
    print("\(lang.language): \(lang.name)")
    print("  Supports formality: \(lang.supportsFormality)")
}

Check Usage

let usage = try await deepl.getUsage()
 
print("Characters used: \(usage.characterCount)")
print("Character limit: \(usage.characterLimit)")
print("Documents used: \(usage.documentCount ?? 0)")
print("Document limit: \(usage.documentLimit ?? 0)")

Options Reference

Formality Options

ValueDescription
.defaultDefault formality
.moreMore formal
.lessLess formal
.preferMorePrefer formal if available
.preferLessPrefer informal if available

Tag Handling

ValueDescription
.xmlHandle XML tags
.htmlHandle HTML tags

Split Sentences

ValueDescription
.offNo splitting
.onSplit on punctuation
.nonewlinesSplit, but not on newlines

Supported Document Types

FormatExtension
Microsoft Word.docx
Microsoft PowerPoint.pptx
PDF.pdf
Plain Text.txt
HTML.html, .htm
XLIFF.xlf, .xliff
SRT (Subtitles).srt

Pricing

DeepL API pricing is based on character count:

  • Free: 500,000 characters/month
  • Pro: €5.49/month + €20 per million characters
  • Business: Volume discounts available

Check their pricing page for current rates.