Skip to content

Commit

Permalink
Added branch id support for Pseudo-localization download (#472)
Browse files Browse the repository at this point in the history
Co-authored-by: Andrii Bodnar <[email protected]>
  • Loading branch information
Volodymyr95 and andrii-bodnar authored Sep 14, 2022
1 parent 4bae6d6 commit 2367685
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
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 @@ -69,7 +69,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

0 comments on commit 2367685

Please sign in to comment.