amplexor / xconnect

一个用于 AMPLEXOR 翻译服务的 PHP 客户端(见 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-09-15 18:19:29 UTC


README

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

SensioLabsInsight

此库实现了对 AMPLEXOR 翻译服务 的 PHP 客户端。

安装

通过 Composer

$ composer require amplexor/xconnect

用法

AMPLEXOR 翻译服务提供 (S)FTP 环境,用于上传翻译请求和下载翻译响应。文件打包在 ZIP 归档中。这些归档总是包含关于请求的详细信息(order.xml)和响应(响应文件名.xml)。

amplexor/xconnect 库抽象了文件创建和传输过程。

创建并发送翻译请求

创建一个新的翻译请求并将其发送到 AMPLEXOR 翻译服务。

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'));

扫描 AMPLEXOR 翻译服务中的处理过的翻译

连接到 AMPLEXOR 翻译服务并检索翻译文件的列表。

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();

接收处理过的翻译

连接到 AMPLEXOR 翻译服务,下载处理过的翻译并提取内容。

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');

测试

运行所有测试(请确保您已使用 composer 下载了依赖项,见贡献指南)

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

贡献

如果您想贡献,请 Fork 此存储库并创建 pull request。

通过克隆 Forked 存储库并运行 composer 来设置您的本地开发环境以获取依赖项

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

致谢

许可证

MIT 许可证(MIT)。请参阅 许可证文件 以获取更多信息。