Skip to content

Commit

Permalink
feat: download translations alias (#862)
Browse files Browse the repository at this point in the history
  • Loading branch information
katerina20 authored Oct 31, 2024
1 parent c22e3c4 commit 3ec7e64
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import picocli.CommandLine;

@CommandLine.Command(
name = "sources",
name = CommandNames.SOURCES,
sortOptions = false
)
public class DownloadSourcesSubcommand extends ActCommandWithFiles {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
sortOptions = false,
aliases = CommandNames.ALIAS_DOWNLOAD,
subcommands = {
DownloadSourcesSubcommand.class
DownloadSourcesSubcommand.class,
DownloadTranslationsSubcommand.class
}
)
class DownloadSubcommand extends ActCommandWithFiles {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.crowdin.cli.commands.picocli;

import com.crowdin.cli.client.ProjectClient;
import com.crowdin.cli.commands.Actions;
import com.crowdin.cli.commands.NewAction;
import com.crowdin.cli.commands.functionality.FsFiles;
import com.crowdin.cli.properties.ParamsWithFiles;
import com.crowdin.cli.properties.PropertiesWithFiles;
import picocli.CommandLine;
import picocli.CommandLine.Command;

import java.util.ArrayList;
import java.util.List;

@Command(
name = CommandNames.TRANSLATIONS,
sortOptions = false
)
public class DownloadTranslationsSubcommand extends ActCommandWithFiles {

@CommandLine.Option(names = {"-b", "--branch"}, descriptionKey = "branch", paramLabel = "...", order = -2)
protected String branchName;

@CommandLine.Option(names = {"--ignore-match"}, descriptionKey = "crowdin.download.ignore-match", order = -2)
protected boolean ignoreMatch;

@CommandLine.Option(names = {"-l", "--language"}, descriptionKey = "crowdin.download.language", paramLabel = "...", order = -2)
protected List<String> languageIds;

@CommandLine.Option(names = {"-e", "--exclude-language"}, descriptionKey = "crowdin.download.exclude-language", paramLabel = "...", order = -2)
protected List<String> excludeLanguageIds;

@CommandLine.Option(names = {"--pseudo"}, descriptionKey = "crowdin.download.pseudo", order = -2)
protected boolean pseudo;

@CommandLine.Option(names = {"--skip-untranslated-strings"}, descriptionKey = "params.skipUntranslatedStrings", order = -2)
protected Boolean skipTranslatedOnly;

@CommandLine.Option(names = {"--skip-untranslated-files"}, descriptionKey = "params.skipUntranslatedFiles", order = -2)
protected Boolean skipUntranslatedFiles;

@CommandLine.Option(names = {"--export-only-approved"}, descriptionKey = "params.exportOnlyApproved", order = -2)
protected Boolean exportApprovedOnly;

@CommandLine.Option(names = {"--keep-archive"}, descriptionKey = "params.keepArchive", order = -2)
protected boolean keepArchive;

@CommandLine.Option(names = {"--all"}, descriptionKey = "crowdin.download.all", order = -2)
protected boolean all;

@CommandLine.Option(names = {"--dryrun"}, descriptionKey = "dryrun")
protected boolean dryrun;

@CommandLine.Option(names = {"--tree"}, descriptionKey = "tree.dryrun")
protected boolean treeView;

@CommandLine.Option(names = {"--plain"}, descriptionKey = "crowdin.list.usage.plain")
protected boolean plainView;

@Override
protected NewAction<PropertiesWithFiles, ProjectClient> getAction(Actions actions) {
return (dryrun)
? actions.listTranslations(noProgress, treeView, false, plainView, all, true, false)
: actions.download(new FsFiles(), noProgress, languageIds, excludeLanguageIds, pseudo, branchName, ignoreMatch, isVerbose, plainView, all, keepArchive);
}

@Override
protected boolean isAnsi() {
return super.isAnsi() && !plainView;
}

@Override
protected void updateParams(ParamsWithFiles params) {
params.setExportOptions(skipTranslatedOnly, skipUntranslatedFiles, exportApprovedOnly);
}

@Override
protected List<String> checkOptions() {
List<String> errors = new ArrayList<>();
if (languageIds != null && excludeLanguageIds != null) {
errors.add(RESOURCE_BUNDLE.getString("error.download.include_exclude_lang_conflict"));
}
return errors;
}
}
3 changes: 3 additions & 0 deletions src/main/resources/messages/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ crowdin.download.exclude-language=Skip the language during download. Can be spec
crowdin.download.pseudo=Download pseudo-localized translation files
crowdin.download.all=Download files even if local sources are missing

crowdin.download.translations.usage.description=Download the latest translations from Crowdin to the specified place
crowdin.download.translations.usage.customSynopsis=@|fg(green) crowdin |@(@|fg(green) download|@|@|fg(green) pull|@) translations [CONFIG OPTIONS] [OPTIONS]

# CROWDIN DOWNLOAD SOURCES COMMAND
crowdin.download.sources.usage.description=Download sources from Crowdin to the specified place
crowdin.download.sources.usage.customSynopsis=@|fg(green) crowdin |@(@|fg(green) download|@|@|fg(green) pull|@) @|fg(green) sources|@ [CONFIG OPTIONS] [OPTIONS]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.crowdin.cli.commands.picocli;

import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.List;

import static com.crowdin.cli.commands.picocli.GenericCommand.RESOURCE_BUNDLE;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Mockito.verify;

class DownloadTranslationsSubcommandTest extends PicocliTestUtils {

@Test
public void testDownload() {
this.execute(CommandNames.DOWNLOAD, CommandNames.TRANSLATIONS, "--debug");
verify(actionsMock)
.download(any(), anyBoolean(), any(), any(), anyBoolean(), any(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean());
this.check(true);
}

@Test
public void testDownloadDryrun() {
this.execute(CommandNames.DOWNLOAD, CommandNames.TRANSLATIONS, "--dryrun");
verify(actionsMock)
.listTranslations(anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean());
this.check(true);
}

@Test
public void testSubCommandCheckInvalidOptions() {
DownloadTranslationsSubcommand downloadSubcommand = new DownloadTranslationsSubcommand();
downloadSubcommand.languageIds = Arrays.asList("uk", "es-ES");
downloadSubcommand.excludeLanguageIds = Arrays.asList("en");
List<String> errors = downloadSubcommand.checkOptions();
assertThat(errors, Matchers.equalTo(Arrays.asList(RESOURCE_BUNDLE.getString("error.download.include_exclude_lang_conflict"))));
}
}
8 changes: 4 additions & 4 deletions website/mantemplates/crowdin-download-translations.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
:includedir: ../generated-picocli-docs
:command: crowdin-download
:command: crowdin-download-translations

== crowdin download translations

Expand All @@ -24,12 +24,12 @@ include::{includedir}/{command}.adoc[tag=picocli-generated-man-section-footer]
Download multiple languages:

----
crowdin download -l de -l fr -l it
crowdin download --language=de --language=fr --language=it
crowdin download translations -l de -l fr -l it
crowdin download translations --language=de --language=fr --language=it
----

Download all translations even if the corresponding source files are missing locally:

----
crowdin download --all
crowdin download translations --all
----

0 comments on commit 3ec7e64

Please sign in to comment.