Skip to content

๐Ÿง  DeepL API Client Library supporting PHP >= 5.3 && PHP < 8.0

License

Notifications You must be signed in to change notification settings

sjuchem/deepl-php-lib

ย 
ย 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

deepl-php-lib

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

Simple PHP Library for DeepL API. You can translate one or multiple text strings (up to 50) per request.

๐Ÿ‡ฉ๐Ÿ‡ช๐Ÿ‡ฌ๐Ÿ‡ง๐Ÿ‡บ๐Ÿ‡ธ๐Ÿ‡ช๐Ÿ‡ธ๐Ÿ‡ฒ๐Ÿ‡ฝ๐Ÿ‡ซ๐Ÿ‡ท๐Ÿ‡ฎ๐Ÿ‡น๐Ÿ‡ฏ๐Ÿ‡ต๐Ÿ‡ณ๐Ÿ‡ฑ๐Ÿ‡ต๐Ÿ‡ฑ๐Ÿ‡ต๐Ÿ‡น๐Ÿ‡ง๐Ÿ‡ท๐Ÿ‡ท๐Ÿ‡บ๐Ÿ‡จ๐Ÿ‡ณ

Official DeepL API

CHANGELOG

Install

Use composer if you want to use this library in your project.

composer require babymarkt/deepl-php-lib

Usage

Create an instance with your auth key:

$authKey = '<AUTH KEY>';
$deepl   = new DeepL($authKey);

Translate

Translate one Text:

$translatedText = $deepl->translate('Hallo Welt', 'de', 'en');
echo $translatedText[0]['text'].PHP_EOL;

Translate multiple Texts:

$text = array(
    'Hallo Welt',
    'Wie geht es dir',
    'Macht doch einfach mal'
);

$translations = $deepl->translate($text, 'de', 'en');

foreach ($translations as $translation) {
    echo $translation['text'].PHP_EOL;
}
param Description
$text Text to be translated. Only UTF8-encoded plain text is supported. The parameter may be specified as an Array and translations are returned in the same order as they are requested. Each of the array values may contain multiple sentences. Up to 50 texts can be sent for translation in one request.
$sourceLang Language of the text to be translated.
default: de
$targetLang The language into which the text should be translated.
default: en
$tagHandling Sets which kind of tags should be handled. Options currently available: "xml"
$ignoreTags Array of XML tags that indicate text not to be translated.
default: null
$formality Sets whether the translated text should lean towards formal or informal language. This feature currently works for all target languages except "EN" (English), "EN-GB" (British English), "EN-US" (American English), "ES" (Spanish), "JA" (Japanese) and "ZH" (Chinese).

Possible options are:
"default" (default)
"more" - for a more formal language
"less" - for a more informal language
$splitSentences Array of XML tags which always cause splits
default: null
$preserveFormatting Sets whether the translation engine should respect the original formatting, even if it would usually correct some aspects. Possible values are:
"0" (default)
"1"
The formatting aspects affected by this setting include:
Punctuation at the beginning and end of the sentence
Upper/lower case at the beginning of the sentence
$nonSplittingTags Comma-separated list of XML tags which never split sentences.
default: null
$outlineDetection See: https://www.deepl.com/docs-api/handling-xml/outline-detection/
default: 1
$splittingTags Array of XML tags which always cause splits.
default: null

Supported languages

In Version 2 we removed the internal List of supported Languages. Instead, you can now get an array with the supported Languages directly form DeepL:

$languagesArray = $deepl->languages();

foreach ($languagesArray as $language) {
    echo 'Name: '.$language['name'].' Api-Shorthand: '.$language['language'].PHP_EOL;
}

You can check for the supported Source-Languages:

$sourceLanguagesArray = $deepl->languages('source');

foreach ($sourceLanguagesArray as $srouceLanguage) {
    echo 'Name: '.$srouceLanguage['name'].' Api-shorthand: '.$srouceLanguage['language'].PHP_EOL;
}

Check for the supported Target-Languages:

$targetLanguagesArray = $deepl->languages('target');

foreach ($targetLanguagesArray as $targetLanguage) {
    echo 'Name: '.$targetLanguage['name'].' Api-Shorthand: '.$targetLanguage['language'].PHP_EOL;
}

Monitoring usage

You can now check ow much you translate, as well as the limit:

$usageArray = $deepl->usage();

echo 'You have used '.$usageArray['character_count'].' of '.$usageArray['character_limit'].' in the current billing period.'.PHP_EOL;
 

Testing

Run PHP_CodeSniffer Tests:

composer cs

Run PHPMD Tests:

composer md

Run PHPUnit Tests:

composer test

Run all tests:

composer test:all

Credits

License

The MIT License (MIT). Please see License File for more information.

About

๐Ÿง  DeepL API Client Library supporting PHP >= 5.3 && PHP < 8.0

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%