Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): Added support for ConcordanceSearch of TMs - partial completion of #122 #202

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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/TranslationMemoryApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,24 @@ 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 concordanceSearch(int $projectId, array $params = []): ?TmConcordanceResultResource
{
$path = sprintf('projects/%d/tms/concordance', $projectId);
return $this->_post($path, TranslationMemory::class, $params);
}
}
44 changes: 44 additions & 0 deletions tests/CrowdinApiClient/Api/TranslationMemoryApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,4 +303,48 @@ public function testClear()
$this->mockRequestDelete('/tms/4/segments');
$this->crowdin->translationMemory->clear(4);
}

public function testConcordanceSearch()
{
$params = [
'sourceLanguageId' => 'en',
'targetLanguageId' => 'uk',
'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->concordanceSearch(4, $params);
$this->assertInstanceOf(TmConcordanceResultResource::class, $export);
}
}
Loading