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
12 changes: 12 additions & 0 deletions src/CrowdinApiClient/Api/TranslationApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use CrowdinApiClient\Model\DownloadFile;
use CrowdinApiClient\Model\DownloadFileTranslation;
use CrowdinApiClient\Model\PreTranslation;
use CrowdinApiClient\Model\PreTranslationReport;
use CrowdinApiClient\Model\TranslationProjectBuild;
use CrowdinApiClient\Model\TranslationProjectDirectory;
use CrowdinApiClient\ModelCollection;
Expand Down Expand Up @@ -75,6 +76,17 @@ public function updatePreTranslation(int $projectId, PreTranslation $preTranslat
return $this->_update($path, $preTranslation);
}

/**
* Pre-Translation Report
* @link https://developer.crowdin.com/api/v2/#operation/api.projects.pre-translations.patch API Documentation
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.pre-translations.patch API Documentation Enterprise
*/
public function getPreTranslationReport(int $projectId, string $preTranslationId): ?PreTranslationReport
{
$path = sprintf('projects/%d/pre-translations/%s/report', $projectId, $preTranslationId);
return $this->_get($path, PreTranslationReport::class);
}

/**
* Build Project Directory Translation
* @link https://developer.crowdin.com/api/v2/#operation/api.projects.translations.builds.directories.post API Documentation
Expand Down
42 changes: 42 additions & 0 deletions src/CrowdinApiClient/Model/PreTranslationReport.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace CrowdinApiClient\Model;

/**
* @package Crowdin\Model
*/
class PreTranslationReport extends BaseModel
{
/**
* @var string
*/
protected $preTranslationType;

/**
* @var PreTranslationReportLanguage[]
*/
protected $languages;

public function __construct(array $data = [])
{
parent::__construct($data);

$this->preTranslationType = (string)$this->getDataProperty('preTranslateType');
$this->languages = array_map(static function (array $language): PreTranslationReportLanguage {
return new PreTranslationReportLanguage($language);
}, (array)$this->getDataProperty('languages'));
}

public function getPreTranslationType(): string
{
return $this->preTranslationType;
}

/**
* @return PreTranslationReportLanguage[]
*/
public function getLanguages(): array
{
return $this->languages;
}
}
37 changes: 37 additions & 0 deletions src/CrowdinApiClient/Model/PreTranslationReportFile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace CrowdinApiClient\Model;

/**
* @package Crowdin\Model
*/
class PreTranslationReportFile extends BaseModel
{
/**
* @var string
*/
protected $id;

/**
* @var PreTranslationReportFileStatistics
*/
protected $statistics;

public function __construct(array $data = [])
{
parent::__construct($data);

$this->id = (string)$this->getDataProperty('id');
$this->statistics = new PreTranslationReportFileStatistics((array)$this->getDataProperty('statistics'));
}

public function getId(): string
{
return $this->id;
}

public function getStatistics(): PreTranslationReportFileStatistics
{
return $this->statistics;
}
}
37 changes: 37 additions & 0 deletions src/CrowdinApiClient/Model/PreTranslationReportFileStatistics.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace CrowdinApiClient\Model;

/**
* @package Crowdin\Model
*/
class PreTranslationReportFileStatistics extends BaseModel
{
/**
* @var int
*/
protected $phrases;

/**
* @var int
*/
protected $words;

public function __construct(array $data = [])
{
parent::__construct($data);

$this->phrases = (int)$this->getDataProperty('phrases');
$this->words = (int)$this->getDataProperty('words');
}

public function getPhrases(): int
{
return $this->phrases;
}

public function getWords(): int
{
return $this->words;
}
}
61 changes: 61 additions & 0 deletions src/CrowdinApiClient/Model/PreTranslationReportLanguage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace CrowdinApiClient\Model;

/**
* @package Crowdin\Model
*/
class PreTranslationReportLanguage extends BaseModel
{
/**
* @var string
*/
protected $id;

/**
* @var PreTranslationReportFile[]
*/
protected $files;

/**
* @var array<string, int>
*/
protected $skippedInfo;

/**
* @var array<string, int>
*/
protected $skippedQaCheckCategories;

public function __construct(array $data = [])
{
parent::__construct($data);

$this->id = (string)$this->getDataProperty('id');
$this->files = array_map(static function (array $file): PreTranslationReportFile {
return new PreTranslationReportFile($file);
}, (array)$this->getDataProperty('files'));
$this->skippedInfo = (array)$this->getDataProperty('skipped');
$this->skippedQaCheckCategories = (array)$this->getDataProperty('skippedQaCheckCategories');
}

public function getId(): string
{
return $this->id;
}

public function getFiles(): array
{
return $this->files;
}

public function getSkippedInfo(): array
{
return $this->skippedInfo;
}

public function getSkippedQaCheckCategories(): array
{
return $this->skippedQaCheckCategories;
}
}
60 changes: 58 additions & 2 deletions tests/CrowdinApiClient/Api/TranslationApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use CrowdinApiClient\Model\DownloadFile;
use CrowdinApiClient\Model\PreTranslation;
use CrowdinApiClient\Model\PreTranslationReport;
use CrowdinApiClient\Model\PreTranslationReportFile;
use CrowdinApiClient\Model\PreTranslationReportLanguage;
use CrowdinApiClient\Model\TranslationProjectBuild;
use CrowdinApiClient\ModelCollection;

Expand Down Expand Up @@ -146,7 +149,7 @@ public function testUpdatePreTranslation(): void
'op' => 'replace',
'path' => '/status',
'value' => 'canceled',
]
],
]),
'response' => json_encode([
'data' => [
Expand All @@ -162,7 +165,7 @@ public function testUpdatePreTranslation(): void
'startedAt' => '2019-11-13T08:17:22Z',
'finishedAt' => '2019-11-13T08:17:22Z',
],
])
]),
]);

$preTranslation = new PreTranslation([
Expand All @@ -187,6 +190,59 @@ public function testUpdatePreTranslation(): void
$this->assertSame(0, $actual->getProgress());
}

public function testGetPreTranslationReport(): void
{
$this->mockRequestGet(
'/projects/2/pre-translations/9e7de270-4f83-41cb-b606-2f90631f26e2/report',
json_encode([
'data' => [
'languages' => [
[
'id' => 'es',
'files' => [
[
'id' => '10191',
'statistics' => [
'phrases' => 6,
'words' => 13,
],
],
],
'skipped' => [
'translation_eq_source' => 2,
'qa_check' => 1,
'hidden_strings' => 0,
'ai_error' => 6,
],
'skippedQaCheckCategories' => [
'duplicate' => 1,
'spellcheck' => 1,
],
],
],
'preTranslateType' => 'ai',
],
])
);

$preTranslationReport = $this->crowdin->translation->getPreTranslationReport(
2,
'9e7de270-4f83-41cb-b606-2f90631f26e2'
);

$this->assertInstanceOf(PreTranslationReport::class, $preTranslationReport);
$this->assertEquals('ai', $preTranslationReport->getPreTranslationType());
$this->assertIsArray($preTranslationReport->getLanguages());
$this->assertInstanceOf(PreTranslationReportLanguage::class, $preTranslationReport->getLanguages()[0]);
$this->assertSame('es', $preTranslationReport->getLanguages()[0]->getId());
$this->assertInstanceOf(
PreTranslationReportFile::class,
$preTranslationReport->getLanguages()[0]->getFiles()[0]
);
$this->assertIsArray($preTranslationReport->getLanguages()[0]->getSkippedInfo());
$this->assertIsArray($preTranslationReport->getLanguages()[0]->getSkippedQaCheckCategories());
}

public function testBuildProjectFileTranslation(): void
{
$this->mockRequest([
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace CrowdinApiClient\Tests\Model;

use CrowdinApiClient\Model\PreTranslationReportFileStatistics;
use PHPUnit\Framework\TestCase;

class PreTranslationReportFileStatisticsTest extends TestCase
{
public $data = [
'phrases' => 6,
'words' => 13,
];

public function testLoadData(): void
{
$preTranslationReportFileStatistics = new PreTranslationReportFileStatistics($this->data);

$this->assertEquals(
$this->data['phrases'],
$preTranslationReportFileStatistics->getPhrases()
);
$this->assertEquals(
$this->data['words'],
$preTranslationReportFileStatistics->getWords()
);
}
}
35 changes: 35 additions & 0 deletions tests/CrowdinApiClient/Model/PreTranslationReportFileTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace CrowdinApiClient\Tests\Model;

use CrowdinApiClient\Model\PreTranslationReportFile;
use PHPUnit\Framework\TestCase;

class PreTranslationReportFileTest extends TestCase
{
public $data = [
'id' => '10191',
'statistics' => [
'phrases' => 6,
'words' => 13,
],
];

public function testLoadData(): void
{
$preTranslationReportFile = new PreTranslationReportFile($this->data);

$this->assertEquals(
$this->data['id'],
$preTranslationReportFile->getId()
);
$this->assertEquals(
$this->data['statistics']['phrases'],
$preTranslationReportFile->getStatistics()->getPhrases()
);
$this->assertEquals(
$this->data['statistics']['words'],
$preTranslationReportFile->getStatistics()->getWords()
);
}
}
Loading