forked from crowdin/crowdin-api-client-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTranslationsApi.java
More file actions
308 lines (287 loc) · 18.1 KB
/
TranslationsApi.java
File metadata and controls
308 lines (287 loc) · 18.1 KB
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
package com.crowdin.client.translations;
import com.crowdin.client.core.CrowdinApi;
import com.crowdin.client.core.http.HttpRequestConfig;
import com.crowdin.client.core.http.exceptions.HttpBadRequestException;
import com.crowdin.client.core.http.exceptions.HttpException;
import com.crowdin.client.core.model.*;
import com.crowdin.client.translations.model.ApplyPreTranslationRequest;
import com.crowdin.client.translations.model.ApplyPreTranslationStringsBasedRequest;
import com.crowdin.client.translations.model.BuildProjectDirectoryTranslationRequest;
import com.crowdin.client.translations.model.BuildProjectFileTranslationRequest;
import com.crowdin.client.translations.model.BuildProjectTranslationRequest;
import com.crowdin.client.translations.model.ExportProjectTranslationRequest;
import com.crowdin.client.translations.model.PreTranslation;
import com.crowdin.client.translations.model.PreTranslationResponseList;
import com.crowdin.client.translations.model.PreTranslationResponseObject;
import com.crowdin.client.translations.model.PreTranslationStatus;
import com.crowdin.client.translations.model.PreTranslationStatusResponseObject;
import com.crowdin.client.translations.model.ProjectBuild;
import com.crowdin.client.translations.model.ProjectBuildResponseList;
import com.crowdin.client.translations.model.ProjectBuildResponseObject;
import com.crowdin.client.translations.model.UploadTranslationsRequest;
import com.crowdin.client.translations.model.UploadTranslationsResponse;
import com.crowdin.client.translations.model.UploadTranslationsResponseObject;
import com.crowdin.client.translations.model.UploadTranslationsStringsRequest;
import com.crowdin.client.translations.model.UploadTranslationsStringsResponse;
import com.crowdin.client.translations.model.UploadTranslationsStringsResponseObject;
import com.crowdin.client.translations.model.PreTranslationReportResponse;
import com.crowdin.client.translations.model.PreTranslationReportResponseObject;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public class TranslationsApi extends CrowdinApi {
public TranslationsApi(Credentials credentials) {
super(credentials);
}
public TranslationsApi(Credentials credentials, ClientConfig clientConfig) {
super(credentials, clientConfig);
}
/**
* @param projectId project identifier
* @param request request body
* @return pre-translation status
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.projects.pre-translations.post" target="_blank"><b>API Documentation</b></a></li>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.pre-translations.post" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseObject<PreTranslationStatus> applyPreTranslation(Long projectId, ApplyPreTranslationRequest request) throws HttpException, HttpBadRequestException {
PreTranslationStatusResponseObject preTranslationStatusResponseObject = this.httpClient.post(this.url + "/projects/" + projectId + "/pre-translations", request, new HttpRequestConfig(), PreTranslationStatusResponseObject.class);
return ResponseObject.of(preTranslationStatusResponseObject.getData());
}
public ResponseObject<PreTranslationStatus> applyPreTranslationStringsBased(Long projectId, ApplyPreTranslationStringsBasedRequest request) throws HttpException, HttpBadRequestException {
PreTranslationStatusResponseObject preTranslationStatusResponseObject = this.httpClient.post(this.url + "/projects/" + projectId + "/pre-translations", request, new HttpRequestConfig(), PreTranslationStatusResponseObject.class);
return ResponseObject.of(preTranslationStatusResponseObject.getData());
}
/**
* @param projectId project identifier
* @param preTranslationId pre-translation identifier
* @return pre-translation status
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.projects.pre-translations.post" target="_blank"><b>API Documentation</b></a></li>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.pre-translations.post" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseObject<PreTranslationStatus> preTranslationStatus(Long projectId, String preTranslationId) throws HttpException, HttpBadRequestException {
PreTranslationStatusResponseObject preTranslationStatusResponseObject = this.httpClient.get(this.url + "/projects/" + projectId + "/pre-translations/" + preTranslationId, new HttpRequestConfig(), PreTranslationStatusResponseObject.class);
return ResponseObject.of(preTranslationStatusResponseObject.getData());
}
/**
* @param projectId project identifier
* @param directoryId directory identifier
* @param request request body
* @return download link
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.projects.translations.builds.directories.post" target="_blank"><b>API Documentation</b></a></li>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.translations.builds.directories.post" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseObject<DownloadLink> buildProjectDirectoryTranslation(Long projectId, Long directoryId, BuildProjectDirectoryTranslationRequest request) throws HttpException, HttpBadRequestException {
String builtUrl = String.format("%s/projects/%d/translations/builds/directories/%d", this.url, projectId, directoryId);
DownloadLinkResponseObject downloadLinkResponseObject = this.httpClient.post(builtUrl, request, new HttpRequestConfig(), DownloadLinkResponseObject.class);
return ResponseObject.of(downloadLinkResponseObject.getData());
}
/**
* @param projectId project identifier
* @param fileId file identifier
* @param etag Etag identifier
* @param request request body
* @return download link
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.projects.translations.builds.files.post" target="_blank"><b>API Documentation</b></a></li>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.translations.builds.files.post" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseObject<DownloadLink> buildProjectFileTranslation(Long projectId, Long fileId, String etag, BuildProjectFileTranslationRequest request) throws HttpException, HttpBadRequestException {
Map<String, String> headers = new HashMap<>();
if (etag != null) {
headers.put("If-None-Match", etag);
}
DownloadLinkResponseObject downloadLinkResponseObject = this.httpClient.post(
this.url + "/projects/" + projectId + "/translations/builds/files/" + fileId,
request,
new HttpRequestConfig(Collections.emptyMap(), headers),
DownloadLinkResponseObject.class
);
return ResponseObject.of(downloadLinkResponseObject.getData());
}
/**
* @param projectId project identifier
* @param branchId filter by branchId
* @param limit maximum number of items to retrieve (default 25)
* @param offset starting offset in the collection (default 0)
* @return list of project builds
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.projects.translations.builds.getMany" target="_blank"><b>API Documentation</b></a></li>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.translations.builds.getMany" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseList<ProjectBuild> listProjectBuilds(Long projectId, Long branchId, Integer limit, Integer offset) throws HttpException, HttpBadRequestException {
Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams(
"branchId", Optional.ofNullable(branchId),
"limit", Optional.ofNullable(limit),
"offset", Optional.ofNullable(offset)
);
ProjectBuildResponseList projectBuildResponseList = this.httpClient.get(this.url + "/projects/" + projectId + "/translations/builds", new HttpRequestConfig(queryParams), ProjectBuildResponseList.class);
return ProjectBuildResponseList.to(projectBuildResponseList);
}
/**
* @param projectId project identifier
* @param request request body
* @return project build status
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.projects.translations.builds.post" target="_blank"><b>API Documentation</b></a></li>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.translations.builds.post" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseObject<ProjectBuild> buildProjectTranslation(Long projectId, BuildProjectTranslationRequest request) throws HttpException, HttpBadRequestException {
ProjectBuildResponseObject projectBuildResponseObject = this.httpClient.post(
this.url + "/projects/" + projectId + "/translations/builds",
request,
new HttpRequestConfig(),
ProjectBuildResponseObject.class
);
return ResponseObject.of(projectBuildResponseObject.getData());
}
/**
* @param projectId project identifier
* @param languageId language identifier
* @param request request body
* @return upload translations response
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.projects.translations.postOnLanguage" target="_blank"><b>API Documentation</b></a></li>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.translations.postOnLanguage" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseObject<UploadTranslationsResponse> uploadTranslations(Long projectId, String languageId, UploadTranslationsRequest request) throws HttpException, HttpBadRequestException {
UploadTranslationsResponseObject projectBuildResponseObject = this.httpClient.post(
this.url + "/projects/" + projectId + "/translations/" + languageId,
request,
new HttpRequestConfig(),
UploadTranslationsResponseObject.class
);
return ResponseObject.of(projectBuildResponseObject.getData());
}
public ResponseObject<UploadTranslationsStringsResponse> uploadTranslationStringsBased(Long projectId, String languageId, UploadTranslationsStringsRequest request) throws HttpException, HttpBadRequestException {
UploadTranslationsStringsResponseObject projectBuildResponseObject = this.httpClient.post(
this.url + "/projects/" + projectId + "/translations/" + languageId,
request,
new HttpRequestConfig(),
UploadTranslationsStringsResponseObject.class
);
return ResponseObject.of(projectBuildResponseObject.getData());
}
/**
* @param projectId project identifier
* @param buildId build identifier
* @return download link
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.projects.translations.builds.download.download" target="_blank"><b>API Documentation</b></a></li>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.translations.builds.download.download" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseObject<DownloadLink> downloadProjectTranslations(Long projectId, Long buildId) throws HttpException, HttpBadRequestException {
DownloadLinkResponseObject downloadLinkResponseObject = this.httpClient.get(this.url + "/projects/" + projectId + "/translations/builds/" + buildId + "/download", new HttpRequestConfig(), DownloadLinkResponseObject.class);
return ResponseObject.of(downloadLinkResponseObject.getData());
}
/**
* @param projectId project identifier
* @param buildId build identifier
* @return project build status
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.projects.translations.builds.get" target="_blank"><b>API Documentation</b></a></li>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.translations.builds.get" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseObject<ProjectBuild> checkBuildStatus(Long projectId, Long buildId) throws HttpException, HttpBadRequestException {
ProjectBuildResponseObject projectBuildResponseObject = this.httpClient.get(this.url + "/projects/" + projectId + "/translations/builds/" + buildId, new HttpRequestConfig(), ProjectBuildResponseObject.class);
return ResponseObject.of(projectBuildResponseObject.getData());
}
/**
* @param projectId project identifier
* @param buildId build identifier
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.projects.translations.builds.delete" target="_blank"><b>API Documentation</b></a></li>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.translations.builds.delete" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public void cancelBuild(Long projectId, Long buildId) throws HttpException, HttpBadRequestException {
this.httpClient.delete(this.url + "/projects/" + projectId + "/translations/builds/" + buildId, new HttpRequestConfig(), Void.class);
}
/**
* Export Project Translation
*
* @param projectId project identifier
* @param request request body
* @return download link
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.projects.translations.exports.post" target="_blank"><b>API Documentation</b></a></li>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.translations.exports.post" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseObject<DownloadLink> exportProjectTranslation(Long projectId, ExportProjectTranslationRequest request) throws HttpException, HttpBadRequestException {
String builtUrl = String.format("%s/projects/%d/translations/exports", this.url, projectId);
DownloadLinkResponseObject response = this.httpClient.post(builtUrl, request, new HttpRequestConfig(), DownloadLinkResponseObject.class);
return ResponseObject.of(response.getData());
}
/**
* List Pre-Translations
*
* @param projectId project identifier
* @param limit maximum number of items to retrieve (default 25)
* @param offset starting offset in the collection (default 0)
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.projects.pre-translations.getMany" target="_blank"><b>API Documentation</b></a></li>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.pre-translations.getMany" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseList<PreTranslation> listPreTranslations(Long projectId, Integer limit, Integer offset) throws HttpException, HttpBadRequestException {
Pagination pagination = new Pagination();
pagination.setLimit(limit);
pagination.setOffset(offset);
return listPreTranslations(projectId, pagination);
}
public ResponseList<PreTranslation> listPreTranslations(Long projectId, Pagination options) throws HttpException, HttpBadRequestException {
Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams(
"limit", Optional.ofNullable(options.getLimit()),
"offset", Optional.ofNullable(options.getOffset())
);
PreTranslationResponseList preTranslationResponseList = this.httpClient.get(this.url + "/projects/" + projectId + "/pre-translations", new HttpRequestConfig(queryParams), PreTranslationResponseList.class);
return PreTranslationResponseList.to(preTranslationResponseList);
}
/**
* Edit Pre-Translation
*
* @param projectId project identifier
* @param preTranslationId pre-translation identifier
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.projects.pre-translations.patch" target="_blank"><b>API Documentation</b></a></li>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.pre-translations.patch" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseObject<PreTranslation> editPreTranslation(Long projectId, String preTranslationId, List<PatchRequest> request) throws HttpException, HttpBadRequestException {
PreTranslationResponseObject preTranslationResponseObject = this.httpClient.patch(
this.url + "/projects/" + projectId + "/pre-translations/" + preTranslationId,
request,
new HttpRequestConfig(),
PreTranslationResponseObject.class
);
return ResponseObject.of(preTranslationResponseObject.getData());
}
/**
* Get Pre-Translation Report
*
* @param projectId project identifier
* @param preTranslationId Pre-translation identifier
*/
public ResponseObject<PreTranslationReportResponse> getPreTranslationReport(Long projectId, String preTranslationId) throws HttpException , HttpBadRequestException{
PreTranslationReportResponseObject response = this.httpClient.get(
this.url + "/projects/" + projectId + "/pre-translations/" + preTranslationId + "/report",
new HttpRequestConfig(),
PreTranslationReportResponseObject.class
);
return ResponseObject.of(response.getData());
}
}