babymarkt/deepl-php-lib
最新稳定版本:v4.0.0
Composer 安装命令:
composer require babymarkt/deepl-php-lib
包简介
DeepL API Client Library supporting PHP >= 7.3 && PHP <= 8.1
README 文档
README
Deprecated Library !
Hello everyone,
in the last couple of months we didn't give much attention to this projekt. DeepL on the other hand has developed client libraries for Python, .NET and Node.js (see: API-Doc).
Since there is a PHP-Library in the works Github and our track record with maintaining our library hasn't been as good as it should have been, we decided to abandon this library and switch internally to the official one.
To make clear that we won't continue to work on this repository, we will archive it. If anyone from the community wants to continue our work we can put a line in the README to point to the new maintained repository.
Otherwise, we recommend you to check out the new library coming from DeepL.
Thank you to everyone who contributed to this project over the years.
Simple PHP Library for DeepL API. You can translate one or multiple text strings (up to 50) per request.
????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
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:
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-free.deepl.com');
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: "" (DeepL will auto-detect) |
| $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 $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; }
Monitoring usage
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;
Glossary
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) |
Configuring cURL requests
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');
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.
babymarkt/deepl-php-lib 适用场景与选型建议
babymarkt/deepl-php-lib 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 282.13k 次下载、GitHub Stars 达 48, 最近一次更新时间为 2026 年 01 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「i18n」 「translation」 「translator」 「deepl」 「deeply」 「babymarkt」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 babymarkt/deepl-php-lib 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 babymarkt/deepl-php-lib 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 babymarkt/deepl-php-lib 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Easy to use i18n translation PHP class for multi-language websites
A custom URL rule class for Yii 2 which allows to create translated URL rules
A Laravel Eloquent model trait for translatable resource
Bureaux A Partager Edit - Parse, validate, manipulate, and display dates in PHP w/ i18n support. Inspired by moment.js
Nette Framework adapter for I18n package
Yii2 integration for AirBnB Polyglot.js
统计信息
- 总下载量: 282.13k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 50
- 点击次数: 30
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-04