Skip to content

Commit

Permalink
Implemented concordanceSearchTM in the standard file-based API
Browse files Browse the repository at this point in the history
  • Loading branch information
DDEV User committed Dec 20, 2024
1 parent a93d9ec commit 768b9ef
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/CrowdinApiClient/Api/TranslationMemoryApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,25 @@ 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://support.crowdin.com/developer/api/v2/#tag/Translation-Memory/operation/api.projects.tms.concordance.post API Documentation
* @link https://support.crowdin.com/developer/enterprise/api/v2/#tag/Translation-Memory/operation/api.projects.tms.concordance.post API Documentation Enterprise
*
* @param int $projectId
* @param array $params
* string $params[sourceLanguageId]<br>
* integer $params[targetLanguageId]<br>
* boolean $params[autoSubstitution]<br>
* integer $params[minRelevant]: 40-100<br>
* [string] $params[expressions]
* @return TranslationMemory
*/
public function concordanceSearchTM(int $projectId, array $params = []): ?TranslationMemory
{
$path = sprintf('projects/%d/tms/concordance', $projectId);
return $this->_post($path, TranslationMemory::class, $params);
}
}
45 changes: 45 additions & 0 deletions tests/CrowdinApiClient/Api/TranslationMemoryApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,4 +303,49 @@ public function testClear()
$this->mockRequestDelete('/tms/4/segments');
$this->crowdin->translationMemory->clear(4);
}


public function testConcordanceSearch()
{
$params = [
'sourceLanguageId' => 'en',
'targetLanguageId' => 'ru',
'autoSubstitution' => true,
'minRelevant' => 50,
'expressions' => ['Welcome!']
];

$this->mockRequest([
'path' => '/projects/4/tms/concordance',
'method' => 'post',
'body' => json_encode($params),
'response' => '{
"data": [
{
"data": {
"tm": {
"id": 4,
"name": "Knowledge Base\'s TM"
},
"recordId": 34,
"source": "Welcome!",
"target": "Ласкаво просимо!",
"relevant": 100,
"substituted": "62→100",
"updatedAt": "2022-09-28T12:29:34+00:00"
}
}
],
"pagination": [
{
"offset": 0,
"limit": 25
}
]
}'
]);

$export = $this->crowdin->translationMemory->concordanceSearchTM(4, $params);
$this->assertInstanceOf(TranslationMemory::class, $export);
}
}

0 comments on commit 768b9ef

Please sign in to comment.