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
21 changes: 21 additions & 0 deletions src/main/java/com/crowdin/client/translations/TranslationsApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,27 @@ public ResponseList<PreTranslation> listPreTranslations(Long projectId, Paginati
return PreTranslationResponseList.to(preTranslationResponseList);
}

/**
* Pre-Translation Batch Operations
*
* @param projectId project identifier
* @param request list of patch operations
* @return list of updated pre-translations
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#tag/Translations/operation/api.projects.pre-translations.patchBatch" target="_blank"><b>API Documentation</b></a></li>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#tag/Translations/operation/api.projects.pre-translations.patchBatch" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseList<PreTranslation> batchEditPreTranslations(Long projectId, List<PatchRequest> request) throws HttpException, HttpBadRequestException {
PreTranslationResponseList preTranslationResponseList = this.httpClient.patch(
this.url + "/projects/" + projectId + "/pre-translations",
request,
new HttpRequestConfig(),
PreTranslationResponseList.class
);
return PreTranslationResponseList.to(preTranslationResponseList);
}

/**
* Edit Pre-Translation
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public List<RequestMock> getMocks() {
RequestMock.build(this.url + "/projects/" + projectId + "/translations/builds/" + buildId, HttpDelete.METHOD_NAME),
RequestMock.build(String.format("%s/projects/%d/translations/exports", this.url, projectId), HttpPost.METHOD_NAME, "api/translations/exportProjectTranslationRequest.json", "api/translations/exportProjectTranslationResponse.json"),
RequestMock.build(this.url + "/projects/" + projectId + "/pre-translations", HttpGet.METHOD_NAME, "api/translations/listPreTranslations.json"),
RequestMock.build(this.url + "/projects/" + projectId + "/pre-translations", HttpPatch.METHOD_NAME, "api/translations/batchEditPreTranslationsRequest.json", "api/translations/batchEditPreTranslationsResponse.json"),
RequestMock.build(this.url + "/projects/" + projectId + "/pre-translations/" + preTranslationId, HttpPatch.METHOD_NAME, "api/translations/editPreTranslationRequest.json", "api/translations/editPreTranslationResponse.json"),
RequestMock.build(this.url + "/projects/" + projectId + "/pre-translations/" + preTranslationId + "/report", HttpGet.METHOD_NAME, "api/translations/preTranslationReportResponse.json"),
RequestMock.build(this.url + "/projects/" + projectId + "/translations/imports", HttpPost.METHOD_NAME, "api/translations/importTranslationsRequest.json", "api/translations/importTranslationsResponse.json"),
Expand Down Expand Up @@ -256,6 +257,22 @@ public void editPreTranslationTest() {
assertEquals(fileId, preTranslationResponseObject.getData().getAttributes().getFileIds().get(0));
}

@Test
public void batchEditPreTranslationsTest() {
PatchRequest request = new PatchRequest();
request.setOp(PatchOperation.REPLACE);
request.setPath("/status");
request.setValue("cancelled");

ResponseList<PreTranslation> preTranslationsResponseList = this.getTranslationsApi().batchEditPreTranslations(projectId, Arrays.asList(request));
assertEquals(1, preTranslationsResponseList.getData().size());
PreTranslation preTranslation = preTranslationsResponseList.getData().get(0).getData();
assertEquals(preTranslationId, preTranslation.getIdentifier());

assertEquals(language, preTranslation.getAttributes().getLanguageIds().get(0));
assertEquals(fileId, preTranslation.getAttributes().getFileIds().get(0));
}

@Test
public void getPreTranslationReportTest() {
ResponseObject<PreTranslationReportResponse> response = this.getTranslationsApi().getPreTranslationReport(projectId, preTranslationId);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"op": "replace",
"path": "/status",
"value": "cancelled"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"data": [
{
"data": {
"identifier": "9e7de270-4f83-41cb-b606-2f90631f26e2",
"status": "cancelled",
"progress": 50,
"attributes": {
"method": "tm",
"fileIds": [
2
],
"languageIds": [
"uk"
],
"autoApproveOption": "none",
"fallbackLanguages": null,
"duplicateTranslations": false,
"skipApprovedTranslations": false,
"translateUntranslatedOnly": true,
"translateWithPerfectMatchOnly": false
},
"createdAt": "2024-01-01T01:00:00+00:00",
"updatedAt": "2024-01-01T01:01:00+00:00",
"startedAt": "2024-01-01T01:00:00+00:00",
"finishedAt": "2024-01-01T01:01:00+00:00"
}
}
],
"pagination": {
"offset": 0,
"limit": 100
}
}
Loading