2017 © Pedro PelĂĄez
 

library deepl-api-connector

Unofficial PHP Client for the API of deepl.com

image

scn/deepl-api-connector

Unofficial PHP Client for the API of deepl.com

  • Friday, June 22, 2018
  • by scn
  • Repository
  • 7 Watchers
  • 2 Stars
  • 510 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

deepl-api-connector - Unofficial PHP Client for the API of deepl.com.

Monthly Downloads License Build status, (*1)

  • Information about Deepl: https://www.deepl.com
  • Deepl API Documentation: https://www.deepl.com/api.html

Requirements

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, (*2)

``` bash $ composer require scn/deepl-api-connector, (*3)


## 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 ```php 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., (*4)

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., (*5)

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, (*6)

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, (*7)

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, (*8)

Working with glossaries

See use_glossaries.php, (*9)

Testing

bash $ composer test, (*10)

Credits

License

The MIT License (MIT). Please see License File for more information., (*11)

The Versions

22/06 2018

dev-master

9999999-dev https://github.com/SC-Networks/deepl-api-connector

Unofficial PHP Client for the API of deepl.com

  Sources   Download

MIT

The Requires

 

The Development Requires

translation deepl

22/06 2018

v1.0.1

1.0.1.0 https://github.com/SC-Networks/deepl-api-connector

Unofficial PHP Client for the API of deepl.com

  Sources   Download

MIT

The Requires

 

The Development Requires

translation deepl

04/06 2018

1.0.x-dev

1.0.9999999.9999999-dev https://github.com/SC-Networks/deepl-api-connector

Unofficial PHP Client for the API of deepl.com

  Sources   Download

MIT

The Requires

 

The Development Requires

translation deepl

04/06 2018

v1.0.0

1.0.0.0 https://github.com/SC-Networks/deepl-api-connector

Unofficial PHP Client for the API of deepl.com

  Sources   Download

MIT

The Requires

 

The Development Requires

translation deepl