DeepL API client library for iOS
- You have to get an authentication key from here.
- Make a following file as DeepL-API.plist.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>DeepL-Auth-Key</key>
<string>YOUR AUTHENTICATION KEY</string>
</dict>
</plist>
- Add DeepL-API.plist to your project. (Put it into the main bundle.)
import DeepLAPI
// texts to be translated.
let list: [String] = [
"What are those?",
"Those are two cows.",
"You have two cows.",
"You have to give one to your neighbor."
]
// translate the list to Japanese using auto-detection.
let response = try await DeepLAPI.translate(list, to: .JA)
// translate the list from English to Japanese
let response = try await DeepLAPI.translate(list, from: .EN, to: .JA)
// print translated texts.
for translation in response.transrations {
print(translation.text)
}
// "あれは何?"
// "2頭の牛だ"
// "2頭いるでしょ?"
// "1頭はお隣さんにあげなきゃね。"
import DeepLAPI
let usage = try await DeepLAPI.getUsage()
print(usage.characterCount) // Characters translated
print(usage.characterLimit) // Current maximum number of characters
print(usage.documentCount) // Documents translated
print(usage.documentLimit) // Current maximum number of documents
// for team accounts only
print(usage.teamDocumentCount // Documents translated by all users in the team
print(usage.teamDocumentLimit) // Current maximum number of documents
import DeepLAPI
let languages = try await getSourceLanguages()
for language in languages {
print("\(language.name) [\(language.language)]) // "Japanese [JA]"
}
import DeepLAPI
let languages = try await getTargetLanguages()
for language in languages {
let support = language.supportsFormality ? "(Support Formality)" : ""
print("\(language.name) [\(language.language)] \(support)")
// "German [DE] (Support Formality)"
}
- Xcode 14.2 or later
- iOS 15.0 or later
- WebClient
Web Client to get data from an API endpoint. - URLStringBuilder
Utility to simplify making a URL String with parameters.