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 luegoAdvanced 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
| Code | Language |
|---|---|
BG | Bulgarian |
CS | Czech |
DA | Danish |
DE | German |
EL | Greek |
EN | English |
ES | Spanish |
ET | Estonian |
FI | Finnish |
FR | French |
HU | Hungarian |
ID | Indonesian |
IT | Italian |
JA | Japanese |
KO | Korean |
LT | Lithuanian |
LV | Latvian |
NB | Norwegian |
NL | Dutch |
PL | Polish |
PT | Portuguese |
RO | Romanian |
RU | Russian |
SK | Slovak |
SL | Slovenian |
SV | Swedish |
TR | Turkish |
UK | Ukrainian |
ZH | Chinese |
Target Languages (with variants)
| Code | Language |
|---|---|
EN-GB | English (British) |
EN-US | English (American) |
PT-BR | Portuguese (Brazilian) |
PT-PT | Portuguese (European) |
ZH-HANS | Chinese (Simplified) |
ZH-HANT | Chinese (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
| Value | Description |
|---|---|
.default | Default formality |
.more | More formal |
.less | Less formal |
.preferMore | Prefer formal if available |
.preferLess | Prefer informal if available |
Tag Handling
| Value | Description |
|---|---|
.xml | Handle XML tags |
.html | Handle HTML tags |
Split Sentences
| Value | Description |
|---|---|
.off | No splitting |
.on | Split on punctuation |
.nonewlines | Split, but not on newlines |
Supported Document Types
| Format | Extension |
|---|---|
| Microsoft Word | .docx |
| Microsoft PowerPoint | .pptx |
| 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.