Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add downloading multiple specified languages #493

Merged
merged 1 commit into from
Oct 17, 2022
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
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