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
68 changes: 68 additions & 0 deletions src/CrowdinApiClient/Api/TranslationMemoryApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use CrowdinApiClient\Model\TranslationMemoryConcordance;
use CrowdinApiClient\Model\TranslationMemoryExport;
use CrowdinApiClient\Model\TranslationMemoryImport;
use CrowdinApiClient\Model\TranslationMemorySegment;
use CrowdinApiClient\ModelCollection;

/**
Expand Down Expand Up @@ -96,6 +97,73 @@ public function clear(int $translationMemoryId)
return $this->_delete($path);
}

/**
* List TM Segments
* @link https://developer.crowdin.com/api/v2/#operation/api.tms.segments.getMany API Documentation
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.tms.segments.getMany API Documentation Enterprise
*
* @param int $tmId
* @param array $params
* string $params[orderBy]<br>
* string $params[croql]<br>
* integer $params[limit]<br>
* integer $params[offset]
* @return ModelCollection
*/
public function listSegments(int $tmId, array $params = []): ModelCollection
{
$path = sprintf('tms/%d/segments', $tmId);
return $this->_list($path, TranslationMemorySegment::class, $params);
}

/**
* Get TM Segment
* @link https://developer.crowdin.com/api/v2/#operation/api.tms.segments.get API Documentation
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.tms.segments.get API Documentation Enterprise
*
* @param int $tmId
* @param int $segmentId
* @return TranslationMemorySegment|null
*/
public function getSegment(int $tmId, int $segmentId): ?TranslationMemorySegment
{
$path = sprintf('tms/%d/segments/%d', $tmId, $segmentId);
return $this->_get($path, TranslationMemorySegment::class);
}

/**
* Create TM Segment
* @link https://developer.crowdin.com/api/v2/#operation/api.tms.segments.post API Documentation
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.tms.segments.post API Documentation Enterprise
*
* @param int $tmId
* @param array $data
* array $data[records]<br>
* string $data[records][][languageId]<br>
* string $data[records][][text]
* @return TranslationMemorySegment|null
*/
public function createSegment(int $tmId, array $data): ?TranslationMemorySegment
{
$path = sprintf('tms/%d/segments', $tmId);
return $this->_create($path, TranslationMemorySegment::class, $data);
}

/**
* Delete TM Segment
* @link https://developer.crowdin.com/api/v2/#operation/api.tms.segments.delete API Documentation
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.tms.segments.delete API Documentation Enterprise
*
* @param int $tmId
* @param int $segmentId
* @return null
*/
public function deleteSegment(int $tmId, int $segmentId)
{
$path = sprintf('tms/%d/segments/%d', $tmId, $segmentId);
return $this->_delete($path);
}

/**
* Export TM
* @link https://developer.crowdin.com/api/v2/#operation/api.tms.exports.post API Documentation
Expand Down
61 changes: 61 additions & 0 deletions src/CrowdinApiClient/Model/TranslationMemorySegment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace CrowdinApiClient\Model;

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

/**
* @var TranslationMemorySegmentRecord[]
*/
protected $records;

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

$this->id = (integer)$this->getDataProperty('id');
$this->records = array_map(static function (array $record): TranslationMemorySegmentRecord {
return new TranslationMemorySegmentRecord($record);
}, (array)$this->getDataProperty('records'));
}

/**
* @return int
*/
public function getId(): int
{
return $this->id;
}

/**
* @param int $id
*/
public function setId(int $id): void
{
$this->id = $id;
}

/**
* @return TranslationMemorySegmentRecord[]
*/
public function getRecords(): array
{
return $this->records;
}

/**
* @param TranslationMemorySegmentRecord[] $records
*/
public function setRecords(array $records): void
{
$this->records = $records;
}
}
190 changes: 190 additions & 0 deletions src/CrowdinApiClient/Model/TranslationMemorySegmentRecord.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
<?php

namespace CrowdinApiClient\Model;

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

/**
* @var string
*/
protected $languageId;

/**
* @var string
*/
protected $text;

/**
* @var integer
*/
protected $usageCount;

/**
* @var integer
*/
protected $createdBy;

/**
* @var integer
*/
protected $updatedBy;

/**
* @var ?string
*/
protected $createdAt;

/**
* @var ?string
*/
protected $updatedAt;

public function __construct(array $data = [])
{
parent::__construct($data);
$this->id = (integer)$this->getDataProperty('id');
$this->languageId = (string)$this->getDataProperty('languageId');
$this->text = (string)$this->getDataProperty('text');
$this->usageCount = (integer)$this->getDataProperty('usageCount');
$this->createdBy = (integer)$this->getDataProperty('createdBy');
$this->updatedBy = (integer)$this->getDataProperty('updatedBy');
$this->createdAt = (string)$this->getDataProperty('createdAt');
$this->updatedAt = (string)$this->getDataProperty('updatedAt');
}

/**
* @return int
*/
public function getId(): int
{
return $this->id;
}

/**
* @param int $id
*/
public function setId(int $id): void
{
$this->id = $id;
}

/**
* @return string
*/
public function getLanguageId(): string
{
return $this->languageId;
}

/**
* @param string $languageId
*/
public function setLanguageId(string $languageId): void
{
$this->languageId = $languageId;
}

/**
* @return string
*/
public function getText(): string
{
return $this->text;
}

/**
* @param string $text
*/
public function setText(string $text): void
{
$this->text = $text;
}

/**
* @return int
*/
public function getUsageCount(): int
{
return $this->usageCount;
}

/**
* @param int $usageCount
*/
public function setUsageCount(int $usageCount): void
{
$this->usageCount = $usageCount;
}

/**
* @return int
*/
public function getCreatedBy(): int
{
return $this->createdBy;
}

/**
* @param int $createdBy
*/
public function setCreatedBy(int $createdBy): void
{
$this->createdBy = $createdBy;
}

/**
* @return int
*/
public function getUpdatedBy(): int
{
return $this->updatedBy;
}

/**
* @param int $updatedBy
*/
public function setUpdatedBy(int $updatedBy): void
{
$this->updatedBy = $updatedBy;
}

/**
* @return string|null
*/
public function getCreatedAt(): ?string
{
return $this->createdAt;
}

/**
* @param string|null $createdAt
*/
public function setCreatedAt(?string $createdAt): void
{
$this->createdAt = $createdAt;
}

/**
* @return string|null
*/
public function getUpdatedAt(): ?string
{
return $this->updatedAt;
}

/**
* @param string|null $updatedAt
*/
public function setUpdatedAt(?string $updatedAt): void
{
$this->updatedAt = $updatedAt;
}
}
Loading