Skip to content

Commit

Permalink
string translations updates
Browse files Browse the repository at this point in the history
  • Loading branch information
yevheniyJ committed Jan 19, 2025
1 parent a35b7ed commit b201312
Show file tree
Hide file tree
Showing 10 changed files with 191 additions and 63 deletions.
18 changes: 10 additions & 8 deletions src/main/java/com/crowdin/client/bundles/BundlesApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,7 @@
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.ClientConfig;
import com.crowdin.client.core.model.Credentials;
import com.crowdin.client.core.model.DownloadLink;
import com.crowdin.client.core.model.DownloadLinkResponseObject;
import com.crowdin.client.core.model.PatchRequest;
import com.crowdin.client.core.model.ResponseList;
import com.crowdin.client.core.model.ResponseObject;
import com.crowdin.client.core.model.*;
import com.crowdin.client.sourcefiles.model.Branch;
import com.crowdin.client.sourcefiles.model.BranchResponseList;
import com.crowdin.client.sourcefiles.model.FileInfo;
Expand Down Expand Up @@ -46,7 +40,15 @@ public BundlesApi(Credentials credentials, ClientConfig clientConfig) {
* </ul>
*/
public ResponseList<Bundle> listBundles(Long projectId) throws HttpException, HttpBadRequestException {
BundleResponseList response = this.httpClient.get(this.url + "/projects/" + projectId + "/bundles", new HttpRequestConfig(), BundleResponseList.class);
return listBundles(projectId, new Pagination());
}

public ResponseList<Bundle> listBundles(Long projectId, Pagination options) throws HttpException, HttpBadRequestException {
Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams(
"limit", Optional.ofNullable(options.getLimit()),
"offset", Optional.ofNullable(options.getOffset())
);
BundleResponseList response = this.httpClient.get(this.url + "/projects/" + projectId + "/bundles", new HttpRequestConfig(queryParams), BundleResponseList.class);
return BundleResponseList.to(response);
}

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/crowdin/client/core/model/BooleanInt.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ public static BooleanInt from(String value) {
return value.equals("1") ? BooleanInt.TRUE : BooleanInt.FALSE;
}

public static BooleanInt fromInt(Integer value) {
if (value == null) {
return null;
}
return value == 1 ? BooleanInt.TRUE : BooleanInt.FALSE;
}

@Override
public Integer to(BooleanInt v) {
return v.val;
Expand Down
14 changes: 6 additions & 8 deletions src/main/java/com/crowdin/client/fields/FieldsApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,12 @@ public FieldsApi(Credentials credentials, ClientConfig clientConfig) {
* </ul>
*/
public ResponseList<Field> listFields(String entity, String search, Integer limit, Integer offset) throws HttpException, HttpBadRequestException {
Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams(
"entity", Optional.ofNullable(entity),
"search", Optional.ofNullable(search),
"limit", Optional.ofNullable(limit),
"offset", Optional.ofNullable(offset)
);
FieldResponseObjectList responseObject = this.httpClient.get(this.url + "/fields", new HttpRequestConfig(queryParams), FieldResponseObjectList.class);
return FieldResponseObjectList.to(responseObject);
ListFieldsParams params = new ListFieldsParams();
params.setEntity(entity);
params.setSearch(search);
params.setLimit(limit);
params.setOffset(offset);
return listFields(params);
}

public ResponseList<Field> listFields(ListFieldsParams params) throws HttpException, HttpBadRequestException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,11 @@ public ProjectsGroupsApi(Credentials credentials, ClientConfig clientConfig) {
* </ul>
*/
public ResponseList<Group> listGroups(Long parentId, Integer limit, Integer offset) throws HttpException, HttpBadRequestException {
Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams(
"parentId", Optional.ofNullable(parentId),
"limit", Optional.ofNullable(limit),
"offset", Optional.ofNullable(offset)
);
GroupResponseList groupResponseList = this.httpClient.get(this.url + "/groups", new HttpRequestConfig(queryParams), GroupResponseList.class);
return GroupResponseList.to(groupResponseList);
ListGroupOptions options = new ListGroupOptions();
options.setParentId(parentId);
options.setLimit(limit);
options.setOffset(offset);
return listGroups(options);
}

public ResponseList<Group> listGroups(ListGroupOptions options) throws HttpException, HttpBadRequestException {
Expand Down Expand Up @@ -117,14 +115,12 @@ public ResponseObject<Group> editGroup(Long groupId, List<PatchRequest> request)
* </ul>
*/
public ResponseList<? extends Project> listProjects(Long groupId, Integer hasManagerAccess, Integer limit, Integer offset) throws HttpException, HttpBadRequestException {
Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams(
"groupId", Optional.ofNullable(groupId),
"hasManagerAccess", Optional.ofNullable(hasManagerAccess),
"limit", Optional.ofNullable(limit),
"offset", Optional.ofNullable(offset)
);
ProjectResponseList projectResponseList = this.httpClient.get(this.url + "/projects", new HttpRequestConfig(queryParams), ProjectResponseList.class);
return ProjectResponseList.to(projectResponseList);
ListProjectOptions options = new ListProjectOptions();
options.setGroupId(groupId);
options.setHasManagerAccess(hasManagerAccess);
options.setLimit(limit);
options.setOffset(offset);
return listProjects(options);
}

public ResponseList<? extends Project> listProjects(ListProjectOptions options) throws HttpException, HttpBadRequestException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
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.ClientConfig;
import com.crowdin.client.core.model.Credentials;
import com.crowdin.client.core.model.ResponseList;
import com.crowdin.client.core.model.ResponseObject;
import com.crowdin.client.core.model.*;
import com.crowdin.client.stringtranslations.model.*;

import java.util.Map;
Expand Down Expand Up @@ -53,15 +50,29 @@ public AlignTranslationResponse alignTranslation(Long projectId, AlignTranslatio
* </ul>
*/
public ResponseList<Approval> listTranslationApprovals(Long projectId, Long fileId, Long stringId, String languageId, Long translationId, String labelIds, String excludeLabelIds, Integer limit, Integer offset) throws HttpException, HttpBadRequestException {
ListTranslationApprovalsOptions options = new ListTranslationApprovalsOptions();
options.setFileId(fileId);
options.setStringId(stringId);
options.setLanguageId(languageId);
options.setTranslationId(translationId);
options.setLabelIds(labelIds);
options.setExcludeLabelIds(excludeLabelIds);
options.setLimit(limit);
options.setOffset(offset);
return listTranslationApprovals(projectId, options);
}

public ResponseList<Approval> listTranslationApprovals(Long projectId, ListTranslationApprovalsOptions options) throws HttpException, HttpBadRequestException {
Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams(
"fileId", Optional.ofNullable(fileId),
"stringId", Optional.ofNullable(stringId),
"languageId", Optional.ofNullable(languageId),
"translationId", Optional.ofNullable(translationId),
"labelIds", Optional.ofNullable(labelIds),
"excludeLabelIds", Optional.ofNullable(excludeLabelIds),
"limit", Optional.ofNullable(limit),
"offset", Optional.ofNullable(offset)
"orderBy", Optional.ofNullable(options.getOrderBy()),
"fileId", Optional.ofNullable(options.getFileId()),
"labelIds", Optional.ofNullable(options.getLabelIds()),
"excludeLabelIds", Optional.ofNullable(options.getExcludeLabelIds()),
"stringId", Optional.ofNullable(options.getStringId()),
"languageId", Optional.ofNullable(options.getLanguageId()),
"translationId", Optional.ofNullable(options.getTranslationId()),
"limit", Optional.ofNullable(options.getLimit()),
"offset", Optional.ofNullable(options.getOffset())
);
ApprovalResponseList approvalResponseList = this.httpClient.get(this.url + "/projects/" + projectId + "/approvals", new HttpRequestConfig(queryParams), ApprovalResponseList.class);
return ApprovalResponseList.to(approvalResponseList);
Expand Down Expand Up @@ -126,17 +137,33 @@ public void removeApproval(Long projectId, Long approvalId) throws HttpException
* </ul>
*/
public ResponseList<LanguageTranslations> listLanguageTranslations(Long projectId, String languageId, String stringIds, String labelIds, Long fileId, Long branchId, Long directoryId, String croql, Integer denormalizePlaceholders, Integer limit, Integer offset) throws HttpException, HttpBadRequestException {
ListLanguageTranslationsOptions options = new ListLanguageTranslationsOptions();
options.setStringIds(stringIds);
options.setLabelIds(labelIds);
options.setFileId(fileId);
options.setBranchId(branchId);
options.setDirectoryId(directoryId);
options.setCroql(croql);
options.setDenormalizePlaceholders(BooleanInt.fromInt(denormalizePlaceholders));
options.setLimit(limit);
options.setOffset(offset);
return listLanguageTranslations(projectId, languageId, options);
}

public ResponseList<LanguageTranslations> listLanguageTranslations(Long projectId, String languageId, ListLanguageTranslationsOptions options) throws HttpException, HttpBadRequestException {
String builtUrl = String.format("%s/projects/%d/languages/%s/translations", this.url, projectId, languageId);
Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams(
"stringIds", Optional.ofNullable(stringIds),
"labelIds", Optional.ofNullable(labelIds),
"fileId", Optional.ofNullable(fileId),
"branchId", Optional.ofNullable(branchId),
"directoryId", Optional.ofNullable(directoryId),
"croql", Optional.ofNullable(croql),
"denormalizePlaceholders", Optional.ofNullable(denormalizePlaceholders),
"limit", Optional.ofNullable(limit),
"offset", Optional.ofNullable(offset)
"stringIds", Optional.ofNullable(options.getStringIds()),
"labelIds", Optional.ofNullable(options.getLabelIds()),
"fileId", Optional.ofNullable(options.getFileId()),
"branchId", Optional.ofNullable(options.getBranchId()),
"directoryId", Optional.ofNullable(options.getDirectoryId()),
"passedWorkflow", Optional.ofNullable(options.getPassedWorkflow()),
"minApprovalCount", Optional.ofNullable(options.getMinApprovalCount()),
"croql", Optional.ofNullable(options.getCroql()),
"denormalizePlaceholders", Optional.ofNullable(options.getDenormalizePlaceholders()),
"limit", Optional.ofNullable(options.getLimit()),
"offset", Optional.ofNullable(options.getOffset())
);
LanguageTranslationsResponseList languageTranslationsResponseList = this.httpClient.get(builtUrl, new HttpRequestConfig(queryParams), LanguageTranslationsResponseList.class);
return LanguageTranslationsResponseList.to(languageTranslationsResponseList);
Expand All @@ -155,11 +182,22 @@ public ResponseList<LanguageTranslations> listLanguageTranslations(Long projectI
* </ul>
*/
public ResponseList<StringTranslation> listStringTranslations(Long projectId, Long stringId, String languageId, Integer limit, Integer offset) throws HttpException, HttpBadRequestException {
ListStringTranslationsOptions options = new ListStringTranslationsOptions();
options.setStringId(stringId);
options.setLanguageId(languageId);
options.setLimit(limit);
options.setOffset(offset);
return listStringTranslations(projectId, options);
}

public ResponseList<StringTranslation> listStringTranslations(Long projectId, ListStringTranslationsOptions options) throws HttpException, HttpBadRequestException {
Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams(
"stringId", Optional.ofNullable(stringId),
"languageId", Optional.ofNullable(languageId),
"limit", Optional.ofNullable(limit),
"offset", Optional.ofNullable(offset)
"stringId", Optional.ofNullable(options.getStringId()),
"languageId", Optional.ofNullable(options.getLanguageId()),
"orderBy", Optional.ofNullable(options.getOrderBy()),
"denormalizePlaceholders", Optional.ofNullable(options.getDenormalizePlaceholders()),
"limit", Optional.ofNullable(options.getLimit()),
"offset", Optional.ofNullable(options.getOffset())
);
StringTranslationResponseList stringTranslationResponseList = this.httpClient.get(this.url + "/projects/" + projectId + "/translations", new HttpRequestConfig(queryParams), StringTranslationResponseList.class);
return StringTranslationResponseList.to(stringTranslationResponseList);
Expand Down Expand Up @@ -252,14 +290,27 @@ public ResponseObject<StringTranslation> restoreStringTranslation(Long projectId
* </ul>
*/
public ResponseList<Vote> listTranslationVotes(Long projectId, Long stringId, String languageId, Long translationId, String labelIds, String excludeLabelIds, Integer limit, Integer offset) throws HttpException, HttpBadRequestException {
ListTranslationVotesOptions options = new ListTranslationVotesOptions();
options.setStringId(stringId);
options.setLanguageId(languageId);
options.setTranslationId(translationId);
options.setLabelIds(labelIds);
options.setExcludeLabelIds(excludeLabelIds);
options.setLimit(limit);
options.setOffset(offset);
return listTranslationVotes(projectId, options);
}

public ResponseList<Vote> listTranslationVotes(Long projectId, ListTranslationVotesOptions options) throws HttpException, HttpBadRequestException {
Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams(
"stringId", Optional.ofNullable(stringId),
"languageId", Optional.ofNullable(languageId),
"translationId", Optional.ofNullable(translationId),
"labelIds", Optional.ofNullable(labelIds),
"excludeLabelIds", Optional.ofNullable(excludeLabelIds),
"limit", Optional.ofNullable(limit),
"offset", Optional.ofNullable(offset)
"stringId", Optional.ofNullable(options.getStringId()),
"languageId", Optional.ofNullable(options.getLanguageId()),
"translationId", Optional.ofNullable(options.getTranslationId()),
"fileId", Optional.ofNullable(options.getFileId()),
"labelIds", Optional.ofNullable(options.getLabelIds()),
"excludeLabelIds", Optional.ofNullable(options.getExcludeLabelIds()),
"limit", Optional.ofNullable(options.getLimit()),
"offset", Optional.ofNullable(options.getOffset())
);
VoteResponseList voteResponseList = this.httpClient.get(this.url + "/projects/" + projectId + "/votes", new HttpRequestConfig(queryParams), VoteResponseList.class);
return VoteResponseList.to(voteResponseList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ public class AddStringTranslationRequest {
private String languageId;
private String text;
private PluralCategoryName pluralCategoryName;
private Boolean addToTm;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.crowdin.client.stringtranslations.model;

import com.crowdin.client.core.model.BooleanInt;
import com.crowdin.client.core.model.Pagination;
import lombok.Data;
import lombok.EqualsAndHashCode;

@EqualsAndHashCode(callSuper = true)
@Data
public class ListLanguageTranslationsOptions extends Pagination {

private String stringIds;
private String labelIds;
private Long fileId;
private Long branchId;
private Long directoryId;
private BooleanInt passedWorkflow;
private Integer minApprovalCount;
private String croql;
private BooleanInt denormalizePlaceholders;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.crowdin.client.stringtranslations.model;

import com.crowdin.client.core.model.BooleanInt;
import com.crowdin.client.core.model.Pagination;
import lombok.Data;
import lombok.EqualsAndHashCode;

@EqualsAndHashCode(callSuper = true)
@Data
public class ListStringTranslationsOptions extends Pagination {

private Long stringId;
private String languageId;
private String orderBy;
private BooleanInt denormalizePlaceholders;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.crowdin.client.stringtranslations.model;

import com.crowdin.client.core.model.Pagination;
import lombok.Data;
import lombok.EqualsAndHashCode;

@EqualsAndHashCode(callSuper = true)
@Data
public class ListTranslationApprovalsOptions extends Pagination {

private String orderBy;
private Long fileId;
private String labelIds;
private String excludeLabelIds;
private Long stringId;
private String languageId;
private Long translationId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.crowdin.client.stringtranslations.model;

import com.crowdin.client.core.model.BooleanInt;
import com.crowdin.client.core.model.Pagination;
import lombok.Data;
import lombok.EqualsAndHashCode;

@EqualsAndHashCode(callSuper = true)
@Data
public class ListTranslationVotesOptions extends Pagination {

private Long stringId;
private String languageId;
private Long translationId;
private Long fileId;
private String labelIds;
private String excludeLabelIds;
}

0 comments on commit b201312

Please sign in to comment.