amplexor/xconnect

A PHP client for the AMPLEXOR Translation Services (see http://www.amplexor.com/globalcontent/en/language-services/translation-services.html).

0.2.1 2016-05-03 15:19 UTC

This package is auto-updated.

Last update: 2024-04-15 17:30:42 UTC


README

Latest Version on Packagist Build Status Coverage status Quality Score Software License

SensioLabsInsight

This library implements a PHP client for the AMPLEXOR Translation Services.

Install

Via Composer:

$ composer require amplexor/xconnect

Usage

AMPLEXOR Translation Services provides (S)FTP environments to upload translation requests to and download translation responses. The files are packed in ZIP archives. These archives always contain a file with details about the request (order.xml) and the response (name-of-the-response-file.xml).

The amplexor/xconnect library abstracts this file creation and transfer process.

Create and send a translation request

Create a new translation request and send it to the AMPLEXOR Translation Service.

use Amplexor\XConnect\Request;
use Amplexor\XConnect\Request\File\ZipFile;
use Amplexor\XConnect\Service\SFtpService;


// Create a new translation request.
$sourceLanguage = 'en';
$config = [
    'clientId'          => 'abcde-1234567890-edcba',
    'orderNamePrefix'   => 'my_translation_order',
    'dueDate'           => 0,
    'issuedBy'          => 'me@company.com',
    'isConfidential'    => false,
    'needsConfirmation' => true,
    'needsQuotation'    => false,
];
$request = new Request($sourceLanguage, $config);

// Fill in the request details:
// The Language(s) to translate the content to:
$request->addTargetLanguage('nl');
$request->addTargetLanguage('fr');
// Optional instructions and reference:
$request->addInstruction('Instruction to add.');
$request->setReference('MY-INTERNAL-REF-0123456789');

// Add content to translate from files.
$request->addFile('path/to/file/document.docx');
$request->addFile('path/to/file/document.xml');

// Add content to translate from strings, a filename needs to be passed to
// identify the different content items.
$request->addFileContent('filename.html', $content);
$request->addFileContent('filename.xliff', $content);


// Create a service object by passing the connection details.
// There are 2 Service available depending on the AMPLEXOR Translation Service configuration:
// - FtpService : Transport over FTP (no encryption).
// - SFtpService : Transport over SSH (encryption).
$config = [
    'hostname' => 'hostname.com',
    'port'     => 22,
    'timeout'  => 90,
    'username' => 'USERNAME',
    'password' => 'PASSWORD',
    'directory_send' => 'TO_LSP',
    'directory_send_processed' => 'TO_LSP_processed',
    'directory_receive' => 'FROM_LSP',
    'directory_receive_processed' => 'FROM_LSP_processed',
];
$service = new SFtpService($config);


// Send the request as a zip file.
$result = $service->send(ZipFile::create($request, 'directory/to/store/file'));

Scan AMPLEXOR Translation Service for processed translations

Connect to the AMPLEXOR Translation Service and retrieve a list of translated files.

use Amplexor\XConnect\Service\SFtpService;

// Connect to the AMPLEXOR Translation Service.
$service = new SFtpService($config);

// Get the list of ZIP packages that are ready, this will be an array of 
// filenames. Retrieving these files is possible by using the services receive 
// method. 
$list = $service->scan();

Receive processed translations

Connect to the AMPLEXOR Translation Service, download the processed translation and extract the content.

use Amplexor\XConnect\Response;
use Amplexor\XConnect\Response\File\ZipFile;
use Amplexor\XConnect\Service\SFtpService;

// Connect to the AMPLEXOR Translation Service.
$service = new SFtpService($config);

// Retrieve a single translation file (ZIP package).
$filePath = $service->receive(
    // The filename ready to be picked up.
    'filename.zip', 
    // The local directory where to store the downloaded file.
    '/local/directory/to/store/the/downloaded/file/'
);

// Create a response object as a wrapper around the received file.
$response = new Response(new ZipFile($filePath));

// Get the translations from the Response.
$translations = $response->getTranslations();

// Get the content of the translations.
foreach ($translations as $translation) {
  $content = $translation->getContent();
}

// Let the service know that the response Zip archive is processed.
$service->processed('filename.zip');

Testing

Run all tests (make sure that you first have downloaded the dependencies with composer, see Contributing):

$ cd /path/where/the/repo/is/cloned
$ phpunit

Contributing

Fork this repository and create pull requests if you would like to contribute.

Setup your local development environment by cloning the forked repository and run composer to get the dependencies:

$ cd /path/where/the/repo/is/cloned
$ composer install

Credits

License

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