unbabel/unbabel-php

此包已被废弃且不再维护。未建议任何替代包。

Unbabel PHP SDK

v1.0 2018-06-08 10:21 UTC

This package is not auto-updated.

Last update: 2022-03-12 05:49:59 UTC


README

Project Status: Abandoned – Initial development has started, but there has not yet been a stable, usable release; the project has been abandoned and the author(s) do not intend on continuing development.

Unbabel的PHP SDK是Unbabel HTTP API的包装器。[链接](https://developers.unbabel.com/v2/docs)

要求

  • PHP: 7.x

安装

建议通过Composer进行安装

$ composer require unbabel/unbabel-php

用法

<?php

require 'vendor/autoload.php';

use Unbabel\Unbabel;
use GuzzleHttp\Client;

$httpClient = new Client();
$unbabel = new Unbabel(
    'username', 
    'apiKey',
     false, // Use sandbox server?
     $httpClient
);

$opts = array('callback_url' => 'http://example.com/unbabel_callback.php');
$resp = $unbabel->submitTranslation('This is a test', 'pt', $opts);
if ($resp->getStatusCode() === 201) {
    // Hooray! Now we need to get the uid so when we are called back we know which translation it corresponds to.
    var_dump(json_decode($resp->getBody()->getContents(), true)['uid']);
} else {
    // If you think everything should be working correctly and you still get an error,
    // send email to tech-support@unbabel.com to complain.
    var_dump($resp->getBody());
    
    exit;
}

// Other examples:
var_dump($unbabel->getTopics()->getBody());
var_dump($unbabel->getJobsWithStatus('new')->getBody());
var_dump($unbabel->getTranslation('8a82e622dbBS')->getBody());
var_dump($unbabel->getTones()->getBody());
var_dump($unbabel->getLanguagePairs()->getBody());

$bulk = [
    ['text' => 'This is a test', 'target_language' => 'pt'],
    ['text' => 'This is a test', 'target_language' => 'es']
];
var_dump($unbabel->submitBulkTranslation($bulk)->getBody());

贡献

阅读关于