All Projects → chriskonnertz → Deeply

chriskonnertz / Deeply

Licence: mit
PHP client for the DeepL.com translation API (unofficial)

Programming Languages

language
365 projects

Projects that are alternatives of or similar to Deeply

React Native Vision Camera
📸 The Camera library that sees the vision.
Stars: ✭ 443 (+191.45%)
Mutual labels:  api, ai, library
Pipedrive
Complete Pipedrive API client for PHP
Stars: ✭ 138 (-9.21%)
Mutual labels:  laravel, library, client
Libretranslate
Free and Open Source Machine Translation API. 100% self-hosted, no limits, no ties to proprietary services. Built on top of Argos Translate.
Stars: ✭ 834 (+448.68%)
Mutual labels:  api, translation, translate
Php Google Translate Free
PHP class to use the Google Translator API for free.
Stars: ✭ 182 (+19.74%)
Mutual labels:  api, translation, translate
Adrestia
APIs & SDK for interacting with Cardano.
Stars: ✭ 56 (-63.16%)
Mutual labels:  api, library, client
Mtproto Core
Telegram API JS (MTProto) client library for browser and nodejs
Stars: ✭ 242 (+59.21%)
Mutual labels:  api, library, client
Parrot
Self-hosted Localization Management Platform built with Go and Angular
Stars: ✭ 967 (+536.18%)
Mutual labels:  api, translation, i18n
Gitter Api
[production-ready] Gitter API implementation for php 7.0+ allowing sync, async and streaming access.
Stars: ✭ 11 (-92.76%)
Mutual labels:  api, library, client
Deepl Translator
This module provides promised methods for translating text using DeepL Translator (https://www.deepl.com/translator) undocumented API.
Stars: ✭ 145 (-4.61%)
Mutual labels:  translation, machine-translation, translate
Lara Eye
Filter your Query\Builder using a structured query language
Stars: ✭ 39 (-74.34%)
Mutual labels:  api, laravel, library
Modernmt
Neural Adaptive Machine Translation that adapts to context and learns from corrections.
Stars: ✭ 231 (+51.97%)
Mutual labels:  translation, machine-translation, neural
Amadeus Node
Node library for the Amadeus Self-Service travel APIs
Stars: ✭ 91 (-40.13%)
Mutual labels:  api, ai, library
Linguist
Easy multilingual urls and redirection support for the Laravel framework
Stars: ✭ 188 (+23.68%)
Mutual labels:  translation, i18n, laravel
Laravel Translation Loader
Store your translations in the database or other sources
Stars: ✭ 446 (+193.42%)
Mutual labels:  translation, i18n, laravel
React Translated
A dead simple way to add complex translations (i18n) in a React (DOM/Native) project 🌎🌍🌏
Stars: ✭ 176 (+15.79%)
Mutual labels:  translation, i18n, translate
Texterify
The localization management system.
Stars: ✭ 37 (-75.66%)
Mutual labels:  api, i18n, translate
React Intl Hooks
React hooks for internationalization without the hassle ⚛️🌍
Stars: ✭ 64 (-57.89%)
Mutual labels:  translation, i18n, translate
Traduora
Ever® Traduora - Open-Source Translation Management Platform
Stars: ✭ 1,580 (+939.47%)
Mutual labels:  api, translation, i18n
Notion Js
🤯 Notion API
Stars: ✭ 136 (-10.53%)
Mutual labels:  api, client
Amqp
AMQP 1.0 client library for Go.
Stars: ✭ 135 (-11.18%)
Mutual labels:  library, client

DeepLy

Build Status Version GitHub license

DeepL.com is a next-generation translation service. It provides better translations compared to other popular translation engines. DeepLy is a PHP package that implements a client to interact with DeepL via their API without an API key. Please switch to DeepLy 2 if you have an API key.

IMPORTANT statement regarding DeepL Pro: DeepLy 2 is under development but it is unkown when it will be released. It will support DeepL Pro.

Installation

Through Composer:

composer require chriskonnertz/deeply

From then on you may run composer update to get the latest version of this library.

It is possible to use this library without using Composer but then it is necessary to register an autoloader function.

This library requires PHP 5.6 or higher and the cURL extension.

Example

$deepLy = new ChrisKonnertz\DeepLy\DeepLy();

$translatedText = $deepLy->translate('Hello world!', 'DE', 'EN');
    
echo $translatedText; // Prints "Hallo Welt!"

An interactive PHP demo script is included. It is located at demos/demo_translate.php.

Sophisticated Example

use ChrisKonnertz\DeepLy\DeepLy;

$deepLy = new DeepLy();

try {
    $translatedText = $deepLy->translate('Hello world!', DeepLy::LANG_EN, DeepLy::LANG_AUTO);
    
    echo $translatedText; // Prints "Hallo Welt!"
} catch (\Exception $exception) {
    echo $exception->getMessage();
}

Always wrap calls of the translate method in a try-catch-block, because they might throw an exception if the arguments are invalid or the API call fails. Instead of using hardcoded strings as language arguments better use the language code constants of the DeepLy class. The class also offers methods such as getLangCodes($withAuto = true) and supportsLangCode($langCode).

You may use the proposeTranslations method if you want to get alternative translations for a text. This method cannot operate on more than one sentence at once.

Auto-Detect Language

DeepLy has a method that uses the DeepL API to detect the language of a text:

$languageCode = $deepLy->detectLanguage('Hello world!');

This will return 'EN'. The language of the text has to be one of the supported languages or the result will be incorrect. If you do not need the code of the language but its English name, you may call the $deepLy->getLangName($langCode) method.

The API, in general, can handle and completely translate texts that contain parts with different languages, if the language switch is not within a sentence. The detectLanguage() method will however only return the code of one language. It will throw an exception if it is unable to auto-detect the language. This will rarely happen, it is more likely that the API will return a "false positive": It will rather detect the wrong language than no language at all.

An interactive PHP demo script is included. It is located at demos/demo_detect.php.

Supported Languages

DeepL(y) supports these languages:

Code Language
auto Auto detect
DE German
EN English
FR French
ES Spanish
IT Italian
NL Dutch
PL Polish
PT Portuguese
RU Russian

Note that auto-detection only is possible for the source language.

DeepL says they will add more languages in the future, such as Chinese.

Text Length Limit

According to the DeepL.com website, the length of the text that has to be translated is limited to 5000 characters. Per default DeepLy will throw an exception if the length limit is exceeded. You may call $deepLy->setValidateTextLength(false) to disable this validation.

HTTP Client

Per default DeepLy uses a minimalistic HTTP client based on cURL. If you want to use a different HTTP client, such as Guzzle, create a class that implements the HttpClient\HttpClientInterface and makes use of the methods of the alternative HTTP client. Then use $deepLy->setHttpClient($yourHttpClient) to inject it.

Note: If you experience issues with the integrated cURL client that could be solved by setting the CURLOPT_SSL_VERIFYPEER to false, first read this: snippets.webaware.com.au/../

If it does not help try: $deepLy->getHttpClient()->setSslVerifyPeer(false)

Guzzle

If you want to use Guzzle as the HTTP client: Support for Guzzle is available out-of-the-box. Make sure you have installed Guzzle (preferably via Composer), then copy this code and paste it right after you instantiate DeepLy:

$protocol = $deepLy->getProtocol();
$httpClient = new \ChrisKonnertz\DeepLy\HttpClient\GuzzleHttpClient($protocol);
$deepLy->setHttpClient($httpClient);

Framework Integration

DeepLy comes with support for Laravel 5.x and since it also supports package auto-discovery it will be auto-detected in Laravel 5.5.

In Laravel 5.0-5.4 you manually have to register the service provider ChrisKonnertz\DeepLy\Integrations\Laravel\DeepLyServiceProvider in the "providers" array and the facade ChrisKonnertz\DeepLy\Integrations\Laravel\DeepLyFacade as an alias in the "aliases" array in your config/app.php config file.

You can then access DeepLy like this: $ping = \DeepLy::ping();

Demos

There are several demo scripts included in the demos folder:

  • demo_translate.php: Demonstrates language translation. Write a text and the API will try to translate it into a language of your choice.
  • demo_detect.php: Demonstrates language detection. Write a text and the API will tell you which language it thinks it is.
  • demo_split.php: Demonstrates sentence detection. Write a text and the API will split it into sentences.
  • demo_ping.php: Demonstrates DeepLy's ping() method by pinging the API.

Request Limit

There is a request limit. The threshold of this limit is unknown.

Internals

The "core" of this library consists of these classes:

  • DeepLy - main class
  • HttpClient\CurlHttpClient - HTTP client class
  • Protocol\JsonRpcProtocol - JSON RPC is the protocol used by the DeepL API
  • ResponseBag\AbstractBag - base wrapper class for the responses of the DeepL API
  • ResponseBag\SentencesBag - concrete class for API responses to "split text" requests
  • ResponseBag\TranslationBag - concrete class for API responses to "translate" requests

There are also some exception classes, interfaces, an alternative HTTP client implementation that uses Guzzle and classes for the Laravel integration.

Current State

DeepL.com has officially released their API. They offer a premium service that includes access to this API. However, it is still possible (at your own risk) to access the API without using the premium service.

Premium API access requires authentication with an API key. This will be supported by DeepLy 2.

Disclaimer

This is not an official package. It is 100% open source and non-commercial. The API of DeepL.com can be accessed without an API key but this might change in the future.

DeepL is a product of DeepL GmbH. More info: deepl.com/publisher.html

This package has been heavily inspired by node-deepls and deeplator. Thank you for your great work! Give these implementations a try if you are coding in Node.js or Python.

Notes

  • Texts have to be UTF8-encoded.

  • If you are looking for a real-world example application that uses DeepLy, you may take a look at Translation Factory.

  • The code of this library is formatted according to the code style defined by the PSR-2 standard.

  • Status of this repository: Maintained. Create an issue and you will get a response, usually within 48 hours.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].