tinyapps / deepl-client
DeepL翻译API的简单PHP客户端。
v1.0.3
2022-04-30 23:59 UTC
Requires
- php: ^7.4 || ^8.0
- guzzlehttp/guzzle: ^6.5 || ^7.0
Requires (Dev)
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-09-29 06:08:36 UTC
README
支持PHP 8的简单PHP DeepL API客户端。
安装
composer require tinyapps/deepl-client
使用
use TinyApps\DeepL\Translator; use TinyApps\DeepL\Options; use TinyApps\DeepL\TargetLanguage; $translator = new Translator('your_api_key'); $result = $translator->translate( text: 'Hello World', source: null, // let's DeepL auto-detect the source language target: TargetLanguage::GERMAN, preserveFormatting: false, splitSentences: Options::SPLIT_SENTENCES_DEFAULT, formality: Options::FORMALITY_DEFAULT, ); $result->getText(); // translated text $result->getDetectedSourceLanguage(); // EN
单元测试
运行 DEEPL_AUTH_KEY=[your key] composer test