openeuropa / cdt-client
A PHP client library for communicating with the CDT service.
Requires
- php: >=8.1
- phpdocumentor/reflection-docblock: ^5.3
- symfony/options-resolver: ^6.4 || ^7.3
- symfony/property-access: ^6.4 || ^7.3
- symfony/property-info: ^6.4 || ^7.3
- symfony/serializer: ^6.4 || ^7.3
Requires (Dev)
- guzzlehttp/guzzle: ^7
- guzzlehttp/psr7: ^2
- openeuropa/code-review-library: ^1.0.0-alpha1
- phpunit/phpunit: ^10.4
- slevomat/coding-standard: ^8.15
This package is auto-updated.
Last update: 2026-04-16 09:40:20 UTC
README
Description
CDT Client is a library offering a PHP API to consume Translation Centre For the Bodies of the EU services.
Install
Use Composer to install the package:
$ composer require openeuropa/cdt-client
Usage
All calls should be done by instantiating the client class:
require_once 'vendor/autoload.php'; $client = new \OpenEuropa\CdtClient\ApiClient( new \GuzzleHttp\Client(), new \GuzzleHttp\Psr7\HttpFactory(), new \GuzzleHttp\Psr7\HttpFactory(), [ // For a full list of options see "Configuration". 'apiBaseUrl' => 'https://example.com', 'username' => 'your-user-name', 'password' => 'your-password', 'client' => 'client-name', ] );
In the above example, we're passing the Guzzle HTTP client, request, stream and URI factories. But these can be replaced by any similar factories that are implementing the PSR interfaces. The last parameter is the configuration.
Configuration
Possible configurations:
username(string): Used for authentication.password(string): Used for authentication.client(string): Used for authentication.apiBaseUrl(string, valid URI): The base API url.
Check connection
$response = $client->checkConnection();
Will return true or false depending on the availability of the CDT service.
Get reference data
$response = $client->getReferenceData();
Will return an array of business reference data, serialized into OpenEuropa\CdtClient\Model\Response\ReferenceData.
Translation requests
To validate and send a translation request, run the following code:
use OpenEuropa\CdtClient\Model\Request\Translation; use OpenEuropa\CdtClient\Exception\ValidationErrorsException; $translationRequest = new Translation() try { if ($client->validateTranslationRequest($translationRequest)) { $correlationId = $client->sendTranslationRequest($translationRequest); } } catch (ValidationErrorsException $e) { $errors = $e->getValidationErrors(); // Handle the errors. }
On success, the sendTranslationRequest() method will return the temporary Correlation ID.
Get permanent request identifier
$permanentId = $client->getPermanentIdentifier($correlationId);
Will return a permanent string identifier for the translation request, based on correlation ID. Throws the ValidationErrorsException if the correlation ID is not found.
Get the status of a translation request
$translationStatus = $client->getRequestStatus($permanentId);
Will return information on the status of translation request, based on permanent ID. The information includes the list of files to download. Throws the ValidationErrorsException if the permanent ID is invalid.
Download the file (source or translated)
$file = $client->downloadFile($fileUrl);
Downloads the specified file, if available, based on the filename listed in getRequestStatus(). Throws a ValidationErrorsException if the filename is invalid.
Contributing
Please read the full documentation for details on our code of conduct, and the process for submitting pull requests to us.
Versioning
We use SemVer for versioning.