Simple PHP Library for DeepL API. You can translate one or multiple text strings (up to 50) per request.
馃嚛馃嚜馃嚘馃嚬馃嚚馃嚟馃嚞馃嚙馃嚭馃嚫馃嚜馃嚫馃嚥馃嚱馃嚝馃嚪馃嚠馃嚬馃嚡馃嚨馃嚦馃嚤馃嚨馃嚤馃嚨馃嚬馃嚙馃嚪馃嚪馃嚭馃嚚馃嚦馃嚞馃嚪馃嚛馃嚢馃嚚馃嚳馃嚜馃嚜馃嚝馃嚠馃嚟馃嚭馃嚤馃嚬馃嚤馃嚮馃嚪馃嚧馃嚪馃嚫馃嚫馃嚢馃嚫馃嚜
Use composer if you want to use this library in your project.
composer require babymarkt/deepl-php-libCreate an instance with your auth key:
use \BabyMarkt\DeepL\DeepL;
$authKey = '<AUTH KEY>';
$deepl = new DeepL($authKey);Use the DeepL API Pro:
use \BabyMarkt\DeepL\DeepL;
$authKey = '<AUTH KEY>';
$deepl = new DeepL($authKey,2,'api.deepl.com');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 |
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 $sourceLanguage) {
echo 'Name: '.$sourceLanguage['name'].' Api-shorthand: '.$sourceLanguage['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;
}You can now check how 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;Create a glossary
$glossary = $deepl->createGlossary('MyGlossary', ['Hallo' => 'Hello'], 'de', 'en');| param | Description |
|---|---|
| $name | Glossary name |
| $entries | Array of entries |
| $sourceLanguage | The source language into which the glossary rule apply |
| $targetLanguage | The target language into which the glossary rule apply |
Delete a glossary
$glossary = $deepl->deleteGlossary($glossaryId);| param | Description |
|---|---|
| $glossaryId | Glossary uuid (set by DeepL when glossary is created) |
List glossaries
use \BabyMarkt\DeepL\Glossary;
$glossaries = $deepl->listGlossaries();
foreach ($glossaries as $glossary) {
var_dump($glossary);
}Get glossary meta information: creation date, is glossary ready to use ...
use \BabyMarkt\DeepL\Glossary;
$glossaryInformation = $deepl->glossaryInformation($glossaryId);
var_dump($glossaryInformation);| param | Description |
|---|---|
| $glossaryId | Glossary uuid (set by DeepL when glossary is created) |
Get glossary entries
$entries = $deepl->glossaryEntries($glossaryId);
foreach ($entries as $sourceLangText => $targetLangText) {
echo $sourceLangText .' > '.$targetLangText;
}| param | Description |
|---|---|
| $glossaryId | Glossary uuid (set by DeepL when glossary is created) |
If you need to use a proxy, you can configure the underlying curl client to use one. You can also specify a timeout to avoid waiting for several minutes if Deepl is unreachable
$deepl->setTimeout(10); //give up after 10 seconds
$deepl->setProxy('http://corporate-proxy.com:3128');
$deepl->setProxyCredentials('username:password');Run PHP_CodeSniffer Tests:
composer csRun PHPMD Tests:
composer mdRun PHPUnit Tests:
composer testRun all tests:
composer test:allThe MIT License (MIT). Please see License File for more information.