ResilientLang docsDeveloper documentation (draft, product name is a placeholder)

PHP SDK

Package resilientlang/resilientlang (placeholder name), PHP 7.4+ and 8.x, namespace ResilientLang\, PSR-18, PSR-17 and PSR-7 interfaces only, so you bring your own HTTP client. Needs ext-sodium for bundle verification. Not published to Packagist; no default API URL. See the SDK overview.

composer config repositories.resilientlang path ./sdks/php && composer require resilientlang/resilientlang   # from the repository
composer require guzzlehttp/guzzle nyholm/psr7                                                               # or any PSR-18 client and PSR-17 factories
use GuzzleHttp\Client as Http;
use Nyholm\Psr7\Factory\Psr17Factory;
use ResilientLang\Client;

$f = new Psr17Factory();
// Do NOT let the HTTP client follow redirects: a redirect could carry the key to another host.
$client = new Client('https://api.example.com', getenv('RL_API_KEY'), new Http(['allow_redirects' => false, 'timeout' => 30]), $f, $f);

$site = $client->sites->create('My shop', 'en', ['fr', 'de'], ['https://shop.example']);
$client->strings->submitAll($site['id'], [['text' => 'Add to basket'], ['text' => 'Checkout', 'context' => 'button']]);

$job = $client->translate($site['id'], ['fr', 'de'])['jobs'][0];     // one job per language
$client->jobs->wait($job['id'], 600.0);
$done = $client->jobs->wait($client->publish($site['id'])['id']);
echo $done['state'];                                                  // succeeded | failed | canceled

foreach ($client->translations->listAll($site['id'], 'fr') as $t) {  // generator; follows nextCursor
    echo $t['key'], ' ', $t['status'], ' ', $t['text'], "\n";
}
$export = $client->export($site['id'], 'xliff2', ['fr', 'de']);       // ['data', 'contentType', 'filename']
$client->importFile($site['id'], file_get_contents('fr.po'), ['filename' => 'fr.po', 'lang' => 'fr', 'dryRun' => true]);
print_r($client->quota());                                            // 404 not-found when quotas are off

Results are plain associative arrays shaped like openapi.json.

The HTTP client must not follow redirects; the SDK cannot enforce that for a client you supply, so set it yourself as shown.

Options#

new Client($baseUrl, $apiKey, $http, $requestFactory, $streamFactory, ['maxRetries' => 2, 'maxRetryDelay' => 10.0, 'allowInsecureHttp' => false, 'userAgent' => ...]). The last argument of every write is an optional idempotency key.

Where next#

Error handling, verify webhooks (Webhook::constructEvent) and verify a published bundle (Bundle::parseVerifiedManifest).