scn/deepl-api-connector
Composer 安装命令:
composer require scn/deepl-api-connector
包简介
Unofficial PHP Client for the API of deepl.com
关键字:
README 文档
README
- Information about Deepl: https://www.deepl.com
- Deepl API Documentation: https://www.deepl.com/api.html
Requirements
- php (See the compatibility table below for supported php versions)
- Implementations of PSR17 (Http-Factories) (Available packages) and PSR18 (Http-Client) (Available packages)
- A deepl free/pro api key
Compatibility
| Connector-Version | PHP-Version(s) |
|---|---|
| master (dev) | 8.2, 8.3 |
| 3.x (features and bugfixes) | 7.4, 8.0, 8.1, 8.2, 8.3 |
| 2.x (EOL) | 7.3, 7.4, 8.0, 8.1 |
| 1.x (EOL) | 7.2, 7.3, 7.4 |
Install
Via Composer
$ composer require scn/deepl-api-connector
Usage
Api client creation
The DeeplClientFactory supports auto-detection of installed psr17/psr18 implementations.
Just call the create method and you are ready to go
require_once __DIR__ . '/vendor/autoload.php'; use \Scn\DeeplApiConnector\DeeplClientFactory; $deepl = DeeplClientFactory::create('your-api-key');
Optionally, you can provide already created instances of HttpClient, StreamFactory and RequestFactory as params to the create method.
require_once __DIR__ . '/vendor/autoload.php'; use \Scn\DeeplApiConnector\DeeplClientFactory; $deepl = DeeplClientFactory::create( 'your-api-key', $existingHttpClientInstance, $existingStreamFactoryInstance, $existingRequestFactoryInstance, );
If a custom HTTP client implementation is to be used, this can also be done via the DeeplClientFactory::create method. The Client must support PSR18.
Get Usage of API Key
require_once __DIR__ . '/vendor/autoload.php'; $deepl = \Scn\DeeplApiConnector\DeeplClientFactory::create('your-api-key'); try { $usageObject = $deepl->getUsage(); }
Get Translation
require_once __DIR__ . '/vendor/autoload.php'; $deepl = \Scn\DeeplApiConnector\DeeplClientFactory::create('your-api-key'); try { $translation = new \Scn\DeeplApiConnector\Model\TranslationConfig( 'My little Test', \Scn\DeeplApiConnector\Enum\LanguageEnum::LANGUAGE_DE ..., ..., ); $translationObject = $deepl->getTranslation($translation); }
require_once __DIR__ . '/vendor/autoload.php'; $deepl = \Scn\DeeplApiConnector\DeeplClientFactory::create('your-api-key'); try { $translation = new \Scn\DeeplApiConnector\Model\TranslationConfig( 'My little Test', \Scn\DeeplApiConnector\Enum\LanguageEnum::LANGUAGE_DE ); $translationObject = $deepl->translate('some text', \Scn\DeeplApiConnector\Enum\LanguageEnum::LANGUAGE_DE); }
Optional you also can translate a batch of texts as once, see example/translate_batch.php
Add File to Translation Queue
require_once __DIR__ . '/vendor/autoload.php'; $deepl = \Scn\DeeplApiConnector\DeeplClientFactory::create('your-api-key'); try { $fileTranslation = new \Scn\DeeplApiConnector\Model\FileTranslationConfig( file_get_contents('test.txt'), 'test.txt', \Scn\DeeplApiConnector\Enum\LanguageEnum::LANGUAGE_EN, \Scn\DeeplApiConnector\Enum\LanguageEnum::LANGUAGE_DE ); $fileSubmission = $deepl->translateFile($fileTranslation); $fileSubmission->getDocumentId() }
Check File Translation Status
All translation states are available in FileStatusEnum
require_once __DIR__ . '/vendor/autoload.php'; $deepl = \Scn\DeeplApiConnector\DeeplClientFactory::create('your-api-key'); try { $fileTranslation = new \Scn\DeeplApiConnector\Model\FileTranslationConfig( file_get_contents('test.txt'), 'test.txt', \Scn\DeeplApiConnector\Enum\LanguageEnum::LANGUAGE_EN, \Scn\DeeplApiConnector\Enum\LanguageEnum::LANGUAGE_DE ); $fileSubmission = $deepl->translateFile($fileTranslation); $translationStatus = $deepl->getFileTranslationStatus($fileSubmission); }
Get Translated File Content
require_once __DIR__ . '/vendor/autoload.php'; $deepl = \Scn\DeeplApiConnector\DeeplClientFactory::create('your-api-key'); try { $fileTranslation = new \Scn\DeeplApiConnector\Model\FileTranslationConfig( file_get_contents('test.txt'), 'test.txt', \Scn\DeeplApiConnector\Enum\LanguageEnum::LANGUAGE_EN, \Scn\DeeplApiConnector\Enum\LanguageEnum::LANGUAGE_DE ); $fileSubmission = $deepl->translateFile($fileTranslation); $file = $deepl->getFileTranslation($fileSubmission); echo $file->getContent(); }
Retrieve supported languages
See example/retrieve_supported_languages.php
Working with glossaries
Testing
$ composer test
Credits
License
The MIT License (MIT). Please see License File for more information.
scn/deepl-api-connector 适用场景与选型建议
scn/deepl-api-connector 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 285.82k 次下载、GitHub Stars 达 16, 最近一次更新时间为 2018 年 06 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「translation」 「deepl」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 scn/deepl-api-connector 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 scn/deepl-api-connector 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 scn/deepl-api-connector 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A custom URL rule class for Yii 2 which allows to create translated URL rules
DeepL API client wrapper for Laravel
A Laravel Eloquent model trait for translatable resource
With this Bundle you can automatically translate your content via DeepL Interface.
This extension provides option to translate content element, and tca record texts to Deepl and Google supported languages using Deepl and Googletranslate Api services.
Deepl Automated translations for Laravel lang files
统计信息
- 总下载量: 285.82k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 17
- 点击次数: 25
- 依赖项目数: 7
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2018-06-04