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

added branch id support #472

Merged
merged 11 commits into from
Sep 14, 2022
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ dependencies {

implementation 'info.picocli:picocli:4.6.1'

implementation 'com.github.crowdin:crowdin-api-client-java:1.3.17'
implementation 'com.github.crowdin:crowdin-api-client-java:1.4.1'

testImplementation 'org.junit.jupiter:junit-jupiter:5.7.2'
testImplementation 'org.hamcrest:hamcrest:2.2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private void populateProjectWithStructure(CrowdinProjectFull project) {
project.setFiles(executeRequestFullList((limit, offset) -> this.client.getSourceFilesApi()
.listFiles(this.projectId, null, null, null, null, limit, offset)));
project.setDirectories(executeRequestFullList((limit, offset) -> this.client.getSourceFilesApi()
.listDirectories(this.projectId, null, null, null, limit, offset)));
.listDirectories(this.projectId, null, null, null, null, limit, offset)));
project.setBranches(this.listBranches());
}

Expand Down
21 changes: 16 additions & 5 deletions src/main/java/com/crowdin/cli/commands/actions/DownloadAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,20 @@ public void act(Outputter out, PropertiesWithFiles pb, ProjectClient client) {
out.println(OK.withIcon(RESOURCE_BUNDLE.getString("message.build_archive_pseudo")));
}
PseudoLocalization pl = pb.getPseudoLocalization();
BuildProjectTranslationRequest request = (pl != null)
? RequestBuilder.crowdinTranslationCreateProjectPseudoBuildForm(
BuildProjectTranslationRequest request = null;

if (branchName != null) {
request = (pl != null)
? RequestBuilder.crowdinTranslationCreateProjectPseudoBuildForm(
branch.get().getId(), true, pl.getLengthCorrection(), pl.getPrefix(), pl.getSuffix(), pl.getCharTransformation())
: RequestBuilder.crowdinTranslationCreateProjectPseudoBuildForm(1L, true, null, null, null, null);
} else {
request = (pl != null)
? RequestBuilder.crowdinTranslationCreateProjectPseudoBuildForm(
true, pl.getLengthCorrection(), pl.getPrefix(), pl.getSuffix(), pl.getCharTransformation())
: RequestBuilder.crowdinTranslationCreateProjectPseudoBuildForm(true, null, null, null, null);
}

Pair<File, List<String>> downloadedFiles = this.download(request, client, pb.getBasePath());
for (FileBean fb : pb.getFiles()) {
Map<String, String> filesWithMapping = this.getFiles(fb, pb.getBasePath(), serverLanguageMapping, forLanguages, placeholderUtil, new ArrayList<>(serverSources.keySet()), pb.getPreserveHierarchy());
Expand Down Expand Up @@ -295,8 +305,9 @@ public void act(Outputter out, PropertiesWithFiles pb, ProjectClient client) {

/**
* Download archive, extract it and return information about that temporary directory
* @param request request body to download archive
* @param client api to Crowdin
*
* @param request request body to download archive
* @param client api to Crowdin
* @param basePath base path
* @return pair of temporary directory and list of files in it(relative paths to that directory)
*/
Expand Down Expand Up @@ -355,7 +366,7 @@ private Map<String, String> getFiles(

private String replaceFileName(String filePath, String newName) {
String[] filePathParts = filePath.split("[\\\\/]+");
filePathParts[filePathParts.length-1] = newName;
filePathParts[filePathParts.length - 1] = newName;
return String.join(Utils.PATH_SEPARATOR, filePathParts);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,17 @@ public static ExportProjectTranslationRequest exportProjectTranslation(ExportPro
return copy;
}

public static CrowdinTranslationCraeteProjectPseudoBuildForm crowdinTranslationCreateProjectPseudoBuildForm(
long branchId, Boolean pseudo, Integer lengthCorrection, String prefix, String suffix, CharTransformation charTransformation
) {
CrowdinTranslationCraeteProjectPseudoBuildForm request
= crowdinTranslationCreateProjectPseudoBuildForm(pseudo, lengthCorrection, prefix, suffix, charTransformation);

request.setBranchId(branchId);

return request;
}

public static CrowdinTranslationCraeteProjectPseudoBuildForm crowdinTranslationCreateProjectPseudoBuildForm(
Boolean pseudo, Integer lengthCorrection, String prefix, String suffix, CharTransformation charTransformation
) {
Expand Down