Code Monkey home page Code Monkey logo

deepl-api-client's Introduction

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.