hackenbacker / DeepL-API-client

DeepL API client library for iOS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DeepL-API-client

Swift Swift Package Manager Platforms

DeepL API client library for iOS


Initial Setup

  1. You have to get an authentication key from here.
  2. 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>
  1. Add DeepL-API.plist to your project. (Put it into the main bundle.)

Usage

Requests translation

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頭はお隣さんにあげなきゃね。"

API document

Retrieves usage information

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

API document

Retrieves Supported Languages (Source)

import DeepLAPI

let languages = try await getSourceLanguages()

for language in languages {
    print("\(language.name) [\(language.language)]) // "Japanese [JA]"
}

API document

Retrieves Supported Languages (Target)

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)"
}

API document

Requirements

  • Xcode 14.2 or later
  • iOS 15.0 or later

Dependencies

  • WebClient
    Web Client to get data from an API endpoint.
  • URLStringBuilder
    Utility to simplify making a URL String with parameters.

About

DeepL API client library for iOS

License:MIT License


Languages

Language:Swift 100.0%