-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathTranslationMemoryApi.php
210 lines (195 loc) · 8.05 KB
/
TranslationMemoryApi.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<?php
namespace CrowdinApiClient\Api;
use CrowdinApiClient\Model\DownloadFile;
use CrowdinApiClient\Model\TranslationMemory;
use CrowdinApiClient\Model\TranslationMemoryExport;
use CrowdinApiClient\Model\TranslationMemoryImport;
use CrowdinApiClient\ModelCollection;
/**
* Translation Memory (TM) is a vault of translations that were previously made in other projects.
* Those translations can be reused to speed up the translation process.
* Every translation made in the project is automatically added to the project Translation Memory.
* Use API to create, upload, download, or remove specific TM.
* Translation Memory export and import are asynchronous operations and shall be completed with sequence of API methods.
*
* @package Crowdin\Api
*/
class TranslationMemoryApi extends AbstractApi
{
/**
* List TMs
* @link https://developer.crowdin.com/api/v2/#operation/api.tms.getMany API Documentation
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.tms.getMany API Documentation Enterprise
*
* @param array $params
* integer $params[userId]<br>
* integer $params[groupId]<br>
* integer $params[limit]<br>
* integer $params[offset]
* @return ModelCollection
*/
public function list(array $params = []): ModelCollection
{
return $this->_list('tms', TranslationMemory::class, $params);
}
/**
* Get TM Info
* @link https://developer.crowdin.com/api/v2/#operation/api.tms.get API Documentation
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.tms.get API Documentation Enterprise
*
* @param int $translationMemoryId
* @return TranslationMemory|null
*/
public function get(int $translationMemoryId): ?TranslationMemory
{
return $this->_get('tms/' . $translationMemoryId, TranslationMemory::class);
}
/**
* Add TM
* @link https://developer.crowdin.com/api/v2/#operation/api.tms.post API Documentation
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.tms.post API Documentation Enterprise
*
* @param array $data
* string $data[name]
* @return mixed
*/
public function create(array $data): ?TranslationMemory
{
return $this->_create('tms', TranslationMemory::class, $data);
}
/**
* Edit TM Info
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.tms.patch API Documentation Enterprise
*
* @param TranslationMemory $translationMemory
* @return TranslationMemory|null
*/
public function update(TranslationMemory $translationMemory): ?TranslationMemory
{
return $this->_update('tms/' . $translationMemory->getId(), $translationMemory);
}
/**
* Delete TM
* @link https://developer.crowdin.com/api/v2/#operation/api.tms.delete API Documentation
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.tms.delete API Documentation Enterprise
*
* @param int $translationMemoryId
* @return mixed
*/
public function delete(int $translationMemoryId)
{
return $this->_delete('tms/' . $translationMemoryId);
}
/**
* Clear TM
* @link https://developer.crowdin.com/api/v2/#operation/api.tms.segments.clear API Documentation
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.tms.segments.clear API Documentation Enterprise
*
* @param int $translationMemoryId
* @return mixed
*/
public function clear(int $translationMemoryId)
{
$path = sprintf('tms/%d/segments', $translationMemoryId);
return $this->_delete($path);
}
/**
* Export TM
* @link https://developer.crowdin.com/api/v2/#operation/api.tms.exports.post API Documentation
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.tms.exports.post API Documentation Enterprise
*
* @param int $translationMemoryId
* @param array $params
* string $params[sourceLanguageId]<br>
* string $params[targetLanguageId]<br>
* string $params[format]
* @return TranslationMemoryExport|null
*/
public function export(int $translationMemoryId, array $params = []): ?TranslationMemoryExport
{
$path = sprintf('tms/%d/exports', $translationMemoryId);
return $this->_post($path, TranslationMemoryExport::class, $params);
}
/**
* Check TM Export Status
* @link https://developer.crowdin.com/api/v2/#operation/api.tms.exports.get API Documentation
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.tms.exports.get API Documentation Enterprise
*
* @param int $translationMemoryId
* @param string $exportId
* @return TranslationMemoryExport|null
*/
public function checkExportStatus(int $translationMemoryId, string $exportId): ?TranslationMemoryExport
{
$path = sprintf('tms/%d/exports/%s', $translationMemoryId, $exportId);
return $this->_get($path, TranslationMemoryExport::class);
}
/**
* Download TM
* @link https://developer.crowdin.com/api/v2/#operation/api.tms.exports.getMany API Documentation
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.tms.exports.getMany API Documentation Enterprise
*
* @param int $translationMemoryId
* @param string $exportId
* @return DownloadFile|null
*/
public function download(int $translationMemoryId, string $exportId): ?DownloadFile
{
$path = sprintf('tms/%d/exports/%s/download', $translationMemoryId, $exportId);
return $this->_get($path, DownloadFile::class);
}
/**
* Import TM
* @link https://developer.crowdin.com/api/v2/#operation/api.tms.imports.post API Documentation
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.tms.imports.post API Documentation Enterprise
*
* @param int $translationMemoryId
* @param int $storageId
* @param bool $firstLineContainsHeader
* @param array $scheme
* @return TranslationMemoryImport|null
*/
public function import(int $translationMemoryId, int $storageId, $firstLineContainsHeader = false, array $scheme = []): ?TranslationMemoryImport
{
$path = sprintf('tms/%d/imports', $translationMemoryId);
$params = [
'storageId' => $storageId,
'firstLineContainsHeader' => $firstLineContainsHeader,
'scheme' => $scheme
];
return $this->_create($path, TranslationMemoryImport::class, $params);
}
/**
* Check TM Import Status
* @link https://developer.crowdin.com/api/v2/#operation/api.tms.imports.get API Documentation
* @link https://developer.crowdin.com/enterprise/api/v2/#operation/api.tms.imports.get API Documentation Enterprise
*
* @param int $translationMemoryId
* @param string $importId
* @return TranslationMemoryImport|null
*/
public function checkImportStatus(int $translationMemoryId, string $importId): ?TranslationMemoryImport
{
$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);
}
}