deepl-api-connector - Unofficial PHP Client for the API of deepl.com.
Information about Deepl: https://www.deepl.com Information about Deepl API: https://www.deepl.com/api.html
Install
Via Composer
$ composer require scn/deepl-api-connector
Usage
Get Usage of API Key
require_once __DIR__ . '/vendor/autoload.php';
$deepl = \Scn\DeeplApiConnector\DeeplClient::create('your-api-key');
try {
$usageObject = $deepl->getUsage();
.......
}
Get Translation
require_once __DIR__ . '/vendor/autoload.php';
$deepl = \Scn\DeeplApiConnector\DeeplClient::create('your-api-key');
try {
$translation = new \Scn\DeeplApiConnector\Model\TranslationConfig(
'My little Test',
\Scn\DeeplApiConnector\Enum\LanguageEnum::LANGUAGE_DE
...,
...,
);
$translationObject = $deepl->getTranslation($translation);
.......
OR
$translationObject = $deepl->translate('some text', \Scn\DeeplApiConnector\Model\TranslationConfigInterface::LANGUAGE_DE);
}
Add File to Translation Queue
require_once __DIR__ . '/vendor/autoload.php';
$deepl = \Scn\DeeplApiConnector\DeeplClient::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
require_once __DIR__ . '/vendor/autoload.php';
$deepl = \Scn\DeeplApiConnector\DeeplClient::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);
if ($translationStatus->getStatus() === \Scn\DeeplApiConnector\Enum\FileStatusEnum::FILE_TRANSLATION_DONE)
{
....
}
}
Get Translated File Content
require_once __DIR__ . '/vendor/autoload.php';
$deepl = \Scn\DeeplApiConnector\DeeplClient::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();
.....
}
Testing
$ composer test
Credits
License
The MIT License (MIT). Please see License File for more information.