PHP code example of ashampoo / ats-client

1. Go to this page and download the library: Download ashampoo/ats-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ashampoo / ats-client example snippets


use Ashampoo\AtsClient\Contracts\AtsClientInterface;

class ExportController
{
    public function __construct(private AtsClientInterface $ats) {}

    public function __invoke()
    {
        $response = $this->ats->getTranslations(language: 'de');

        return $response->json();
    }
}

use Ashampoo\AtsClient\Facades\Ats;

$response = Ats::getLangInfo('de');

Ats::getTranslations(
    language: 'de',
    filter: 'untranslated',
    formatId: 'xliff',
    contextSplitting: true,
    updatedSince: '2017-07-21T17:32:28Z',
);

Ats::getAllTranslations(filter: 'untranslated');

use Ashampoo\AtsClient\Requests\TranslationImportRequest;

Ats::importTranslations(new TranslationImportRequest(
    language: 'de',
    importIds: true,
    importTranslations: true,
    overWriteTranslations: false,
    body: [
        'id-1' => 'Hallo Welt',
        'id-2' => 'Guten Tag',
    ],
));

Ats::generateMachineTranslation('de');
Ats::generateAllMachineTranslations();
Ats::generateMemoryTranslation('de');
Ats::generateAllMemoryTranslations();

use Ashampoo\AtsClient\Exceptions\AtsRequestException;
use Ashampoo\AtsClient\Exceptions\MissingQueryParamException;

try {
    $response = Ats::getTranslations('de');
} catch (MissingQueryParamException $e) {
    // caller bug — log, surface to user
} catch (AtsRequestException $e) {
    $status = $e->getResponse()->status();
    $body   = $e->getResponse()->json();
    // decide: retry, surface, escalate
}
bash
php artisan vendor:publish --tag=ats-config