Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions src/CrowdinApiClient/Api/TranslationApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace CrowdinApiClient\Api;

use CrowdinApiClient\Http\ResponseDecorator\ResponseArrayDecorator;
use CrowdinApiClient\Http\ResponseDecorator\ResponseModelListDecorator;
use CrowdinApiClient\Model\DownloadFile;
use CrowdinApiClient\Model\DownloadFileTranslation;
use CrowdinApiClient\Model\PreTranslation;
Expand Down Expand Up @@ -90,6 +91,31 @@ public function getPreTranslationReport(int $projectId, string $preTranslationId
return $this->_get($path, PreTranslationReport::class);
}

/**
* Batch Update Pre-Translations
* @link https://developer.crowdin.com/api/v2/#operation/api.projects.pre-translations.patchBatch API Documentation
*
* @param int $projectId
* @param array $data JSON Patch array with operations (replace)
* @return ModelCollection
*/
public function updatePreTranslations(int $projectId, array $data): ModelCollection
{
$path = sprintf('projects/%d/pre-translations', $projectId);

$options = [
'body' => json_encode($data),
'headers' => $this->getHeaders(),
];

return $this->client->apiRequest(
'patch',
$path,
new ResponseModelListDecorator(PreTranslation::class),
$options
);
}

/**
* Build Project Directory Translation
* @link https://developer.crowdin.com/api/v2/#operation/api.projects.translations.builds.directories.post API Documentation
Expand Down Expand Up @@ -226,8 +252,10 @@ public function getTranslationImportStatus(int $projectId, string $importTransla
* @link https://developer.crowdin.com/api/v2/#operation/api.projects.translations.imports.report.get API Documentation
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.translations.imports.report.get API Documentation Enterprise
*/
public function downloadTranslationImportReport(int $projectId, string $importTranslationId): ?TranslationImportReport
{
public function downloadTranslationImportReport(
int $projectId,
string $importTranslationId
): ?TranslationImportReport {
$path = sprintf('projects/%d/translations/imports/%s/report', $projectId, $importTranslationId);
return $this->_get($path, TranslationImportReport::class);
}
Expand Down Expand Up @@ -325,7 +353,7 @@ public function exportProjectTranslation(int $projectId, array $params = []): Do
* @link https://developer.crowdin.com/api/v2/#operation/api.projects.translations.alignment.post API Documentation
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.translations.alignment.post API Documentation Enterprise
*
* @param int $projectId
* @param int $projectId
* @param array $params
* string $params[sourceLanguageId] required<br>
* string $params[targetLanguageId] required<br>
Expand Down
55 changes: 55 additions & 0 deletions tests/CrowdinApiClient/Api/TranslationApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -657,4 +657,59 @@ public function testDownloadTranslationImportReport(): void
$this->assertInstanceOf(PreTranslationReportLanguage::class, $report->getLanguages()[0]);
$this->assertSame('uk', $report->getLanguages()[0]->getId());
}

public function testUpdatePreTranslations(): void
{
$this->mockRequest([
'uri' => 'https://api.crowdin.com/api/v2/projects/1/pre-translations',
'method' => 'patch',
'response' => json_encode([
'data' => [
[
'data' => [
'identifier' => '9e7de270-4f83-41cb-b606-2f90631f26e2',
'status' => 'canceled',
'progress' => 50,
'attributes' => [
'languageIds' => ['uk'],
'fileIds' => [742],
'method' => 'tm',
'autoApproveOption' => 'all',
'duplicateTranslations' => true,
'skipApprovedTranslations' => true,
'translateUntranslatedOnly' => true,
'translateWithPerfectMatchOnly' => true,
'priority' => 'high',
],
'createdAt' => '2019-09-20T14:05:50+00:00',
'updatedAt' => '2019-09-20T14:05:50+00:00',
'startedAt' => '2019-09-20T14:05:50+00:00',
'finishedAt' => '2019-09-20T14:06:50+00:00',
],
],
],
]),
]);

$data = [
[
'op' => 'replace',
'path' => '/9e7de270-4f83-41cb-b606-2f90631f26e2/status',
'value' => 'canceled',
],
[
'op' => 'replace',
'path' => '/9e7de270-4f83-41cb-b606-2f90631f26e2/priority',
'value' => 'high',
],
];

$preTranslations = $this->crowdin->translation->updatePreTranslations(1, $data);

$this->assertInstanceOf(ModelCollection::class, $preTranslations);
$this->assertCount(1, $preTranslations);
$this->assertInstanceOf(PreTranslation::class, $preTranslations[0]);
$this->assertEquals('9e7de270-4f83-41cb-b606-2f90631f26e2', $preTranslations[0]->getIdentifier());
$this->assertEquals('canceled', $preTranslations[0]->getStatus());
}
}
Loading