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
20 changes: 20 additions & 0 deletions src/CrowdinApiClient/Api/TranslationApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use CrowdinApiClient\Model\DownloadFileTranslation;
use CrowdinApiClient\Model\PreTranslation;
use CrowdinApiClient\Model\PreTranslationReport;
use CrowdinApiClient\Model\TranslationAlignment;
use CrowdinApiClient\Model\TranslationProjectBuild;
use CrowdinApiClient\Model\TranslationProjectDirectory;
use CrowdinApiClient\ModelCollection;
Expand Down Expand Up @@ -269,4 +270,23 @@ public function exportProjectTranslation(int $projectId, array $params = []): Do
$path = sprintf('projects/%d/translations/exports', $projectId);
return $this->_post($path, DownloadFile::class, $params);
}

/**
* Translation Alignment
* @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 array $params
* string $params[sourceLanguageId] required<br>
* string $params[targetLanguageId] required<br>
* string $params[text] required
*
* @return TranslationAlignment|null
*/
public function alignment(int $projectId, array $params): ?TranslationAlignment
{
$path = sprintf('projects/%d/translations/alignment', $projectId);
return $this->_post($path, TranslationAlignment::class, $params);
}
}
30 changes: 30 additions & 0 deletions src/CrowdinApiClient/Api/TranslationMemoryApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace CrowdinApiClient\Api;

use CrowdinApiClient\Http\ResponseDecorator\ResponseModelListDecorator;
use CrowdinApiClient\Model\DownloadFile;
use CrowdinApiClient\Model\TranslationMemory;
use CrowdinApiClient\Model\TranslationMemoryConcordance;
use CrowdinApiClient\Model\TranslationMemoryExport;
use CrowdinApiClient\Model\TranslationMemoryImport;
use CrowdinApiClient\ModelCollection;
Expand Down Expand Up @@ -165,4 +167,32 @@ public function checkImportStatus(int $translationMemoryId, string $importId): ?
$path = sprintf('tms/%d/imports/%s', $translationMemoryId, $importId);
return $this->_get($path, TranslationMemoryImport::class);
}

/**
* Concordance search in TMs
* @link https://developer.crowdin.com/api/v2/#operation/api.projects.tms.concordance.post API Documentation
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.tms.concordance.post API Documentation Enterprise
*
* @param int $projectId
* @param array $params
* string $params[sourceLanguageId] required<br>
* string $params[targetLanguageId] required<br>
* bool $params[autoSubstitution] required Improves TM suggestions<br>
* int $params[minRelevant] required Show TM suggestions with specified minimum match (1-100)<br>
* string[] $params[expressions] required Note: Can't be used with expression in same request<br>
* string $params[expression] Deprecated Note: Can't be used with expressions in same request
* @return ModelCollection|null
*/
public function concordance(int $projectId, array $params): ?ModelCollection
{
return $this->client->apiRequest(
'post',
sprintf('projects/%d/tms/concordance', $projectId),
new ResponseModelListDecorator(TranslationMemoryConcordance::class),
[
'body' => json_encode($params),
'headers' => $this->getHeaders(),
]
);
}
}
101 changes: 101 additions & 0 deletions src/CrowdinApiClient/Model/Alignment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php

declare(strict_types=1);

namespace CrowdinApiClient\Model;

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

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

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

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

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

/**
* @var float
*/
protected $probability;

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

$this->sourceWord = (string)$this->getDataProperty('sourceWord');
$this->sourceLemma = (string)$this->getDataProperty('sourceLemma');
$this->targetWord = (string)$this->getDataProperty('targetWord');
$this->targetLemma = (string)$this->getDataProperty('targetLemma');
$this->match = (int)$this->getDataProperty('match');
$this->probability = (float)$this->getDataProperty('probability');
}

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

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

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

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

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

/**
* @return float
*/
public function getProbability(): float
{
return $this->probability;
}
}
36 changes: 36 additions & 0 deletions src/CrowdinApiClient/Model/TranslationAlignment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace CrowdinApiClient\Model;

/**
* @package Crowdin\Model
*/
class TranslationAlignment extends BaseModel
{
/**
* @var WordAlignment[]
*/
protected $words;

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

$this->words = array_map(
static function (array $word): WordAlignment {
return new WordAlignment($word);
},
(array)$this->getDataProperty('words')
);
}

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

declare(strict_types=1);

namespace CrowdinApiClient\Model;

/**
* @package Crowdin\Model
*/
class TranslationMemoryConcordance extends BaseModel
{
/**
* @var TranslationMemory
*/
protected $tm;

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

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

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

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

/**
* @var string|null
*/
protected $substituted;

/**
* @var string|null
*/
protected $updatedAt;

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

$this->tm = new TranslationMemory($this->getDataProperty('tm'));
$this->recordId = (int)$this->getDataProperty('recordId');
$this->source = (string)$this->getDataProperty('source');
$this->target = (string)$this->getDataProperty('target');
$this->relevant = (int)$this->getDataProperty('relevant');
$this->substituted = $this->getDataProperty('substituted');
$this->updatedAt = $this->getDataProperty('updatedAt');
}

public function getTm(): TranslationMemory
{
return $this->tm;
}

public function getRecordId(): int
{
return $this->recordId;
}

public function getSource(): string
{
return $this->source;
}

public function getTarget(): string
{
return $this->target;
}

public function getRelevant(): int
{
return $this->relevant;
}

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

/**
* @return string|null
*/
public function getUpdatedAt(): ?string
{
return $this->updatedAt;
}
}
50 changes: 50 additions & 0 deletions src/CrowdinApiClient/Model/WordAlignment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

namespace CrowdinApiClient\Model;

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

/**
* @var Alignment[]
*/
protected $alignments;

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

$this->text = (string)$this->getDataProperty('text');
$this->alignments = array_map(
static function (array $alignment): Alignment {
return new Alignment($alignment);
},
(array)$this->getDataProperty('alignments')
);
}

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

/**
* @return Alignment[]
*/
public function getAlignments(): array
{
return $this->alignments;
}
}
Loading