Skip to content

Commit

Permalink
Merge pull request #493 from Epicpkmn11/download-multiple-languages
Browse files Browse the repository at this point in the history
Add downloading multiple specified languages
  • Loading branch information
andrii-bodnar authored Oct 17, 2022
2 parents 292c03f + f16e05d commit ed2c218
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/crowdin/cli/commands/Actions.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public interface Actions {

NewAction<PropertiesWithFiles, ProjectClient> download(
FilesInterface files, boolean noProgress, String languageId, boolean pseudo, String branchName,
FilesInterface files, boolean noProgress, List<String> languageIds, boolean pseudo, String branchName,
boolean ignoreMatch, boolean isVerbose, boolean plainView, boolean userServerSources
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ public class CliActions implements Actions {

@Override
public NewAction<PropertiesWithFiles, ProjectClient> download(
FilesInterface files, boolean noProgress, String languageId, boolean pseudo, String branchName,
FilesInterface files, boolean noProgress, List<String> languageIds, boolean pseudo, String branchName,
boolean ignoreMatch, boolean isVerbose, boolean plainView, boolean useServerSources
) {
return new DownloadAction(files, noProgress, languageId, pseudo, branchName, ignoreMatch, isVerbose, plainView, useServerSources);
return new DownloadAction(files, noProgress, languageIds, pseudo, branchName, ignoreMatch, isVerbose, plainView, useServerSources);
}

@Override
Expand Down
26 changes: 12 additions & 14 deletions src/main/java/com/crowdin/cli/commands/actions/DownloadAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class DownloadAction implements NewAction<PropertiesWithFiles, ProjectClient> {

private FilesInterface files;
private boolean noProgress;
private String languageId;
private List<String> languageIds;
private boolean pseudo;
private String branchName;
private boolean ignoreMatch;
Expand All @@ -70,12 +70,12 @@ class DownloadAction implements NewAction<PropertiesWithFiles, ProjectClient> {
private Outputter out;

public DownloadAction(
FilesInterface files, boolean noProgress, String languageId, boolean pseudo, String branchName,
FilesInterface files, boolean noProgress, List<String> languageIds, boolean pseudo, String branchName,
boolean ignoreMatch, boolean isVerbose, boolean plainView, boolean useServerSources
) {
this.files = files;
this.noProgress = noProgress || plainView;
this.languageId = languageId;
this.languageIds = languageIds;
this.pseudo = pseudo;
this.branchName = branchName;
this.ignoreMatch = ignoreMatch;
Expand Down Expand Up @@ -110,10 +110,11 @@ public void act(Outputter out, PropertiesWithFiles pb, ProjectClient client) {
new PlaceholderUtil(
project.getSupportedLanguages(), project.getProjectLanguages(true), pb.getBasePath());

Optional<Language> language = Optional.ofNullable(languageId)
List<Language> languages = languageIds == null ? null : languageIds.stream()
.map(lang -> project.findLanguageById(lang, true)
.orElseThrow(() -> new RuntimeException(
String.format(RESOURCE_BUNDLE.getString("error.language_not_exist"), lang))));
String.format(RESOURCE_BUNDLE.getString("error.language_not_exist"), lang))))
.collect(Collectors.toList());
Optional<Branch> branch = Optional.ofNullable(this.branchName)
.map(br -> project.findBranchByName(br)
.orElseThrow(() -> new RuntimeException(RESOURCE_BUNDLE.getString("error.not_found_branch"))));
Expand Down Expand Up @@ -153,19 +154,16 @@ public void act(Outputter out, PropertiesWithFiles pb, ProjectClient client) {
}
tempDirs.put(downloadedFiles.getLeft(), downloadedFiles.getRight());
} else {
List<Language> forLanguages = language
.map(Collections::singletonList)
.orElse(project.getProjectLanguages(true));
List<Language> forLanguages = languages != null ? languages : project.getProjectLanguages(true);
if (!plainView) {
out.println((languageId != null)
? OK.withIcon(String.format(RESOURCE_BUNDLE.getString("message.build_language_archive"), languageId))
out.println((languageIds != null)
? OK.withIcon(String.format(RESOURCE_BUNDLE.getString("message.build_language_archive"), String.join(", ", languageIds)))
: OK.withIcon(RESOURCE_BUNDLE.getString("message.build_archive")));
}
CrowdinTranslationCreateProjectBuildForm templateRequest = new CrowdinTranslationCreateProjectBuildForm();
language
.map(Language::getId)
.map(Collections::singletonList)
.ifPresent(templateRequest::setTargetLanguageIds);
if (languages != null) {
templateRequest.setTargetLanguageIds(languages.stream().map(Language::getId).collect(Collectors.toList()));
}
branch
.map(Branch::getId)
.ifPresent(templateRequest::setBranchId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class DownloadSubcommand extends ActCommandWithFiles {
protected boolean ignoreMatch;

@CommandLine.Option(names = {"-l", "--language"}, paramLabel = "...")
protected String languageId;
protected List<String> languageIds;

@CommandLine.Option(names = {"--pseudo"}, descriptionKey = "crowdin.download.pseudo")
protected boolean pseudo;
Expand All @@ -57,7 +57,7 @@ class DownloadSubcommand extends ActCommandWithFiles {
protected NewAction<PropertiesWithFiles, ProjectClient> getAction(Actions actions) {
return (dryrun)
? actions.listTranslations(noProgress, treeView, false, plainView, all, true)
: actions.download(new FsFiles(), noProgress, languageId, pseudo, branchName, ignoreMatch, isVerbose, plainView, all);
: actions.download(new FsFiles(), noProgress, languageIds, pseudo, branchName, ignoreMatch, isVerbose, plainView, all);
}

@CommandLine.Option(names = {"--plain"}, descriptionKey = "crowdin.list.usage.plain")
Expand Down

0 comments on commit ed2c218

Please sign in to comment.