Skip to content

Commit 3ec7e64

Browse files
authoredOct 31, 2024··
feat: download translations alias (#862)
1 parent c22e3c4 commit 3ec7e64

File tree

6 files changed

+136
-6
lines changed

6 files changed

+136
-6
lines changed
 

‎src/main/java/com/crowdin/cli/commands/picocli/DownloadSourcesSubcommand.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import picocli.CommandLine;
1010

1111
@CommandLine.Command(
12-
name = "sources",
12+
name = CommandNames.SOURCES,
1313
sortOptions = false
1414
)
1515
public class DownloadSourcesSubcommand extends ActCommandWithFiles {

‎src/main/java/com/crowdin/cli/commands/picocli/DownloadSubcommand.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
sortOptions = false,
1717
aliases = CommandNames.ALIAS_DOWNLOAD,
1818
subcommands = {
19-
DownloadSourcesSubcommand.class
19+
DownloadSourcesSubcommand.class,
20+
DownloadTranslationsSubcommand.class
2021
}
2122
)
2223
class DownloadSubcommand extends ActCommandWithFiles {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package com.crowdin.cli.commands.picocli;
2+
3+
import com.crowdin.cli.client.ProjectClient;
4+
import com.crowdin.cli.commands.Actions;
5+
import com.crowdin.cli.commands.NewAction;
6+
import com.crowdin.cli.commands.functionality.FsFiles;
7+
import com.crowdin.cli.properties.ParamsWithFiles;
8+
import com.crowdin.cli.properties.PropertiesWithFiles;
9+
import picocli.CommandLine;
10+
import picocli.CommandLine.Command;
11+
12+
import java.util.ArrayList;
13+
import java.util.List;
14+
15+
@Command(
16+
name = CommandNames.TRANSLATIONS,
17+
sortOptions = false
18+
)
19+
public class DownloadTranslationsSubcommand extends ActCommandWithFiles {
20+
21+
@CommandLine.Option(names = {"-b", "--branch"}, descriptionKey = "branch", paramLabel = "...", order = -2)
22+
protected String branchName;
23+
24+
@CommandLine.Option(names = {"--ignore-match"}, descriptionKey = "crowdin.download.ignore-match", order = -2)
25+
protected boolean ignoreMatch;
26+
27+
@CommandLine.Option(names = {"-l", "--language"}, descriptionKey = "crowdin.download.language", paramLabel = "...", order = -2)
28+
protected List<String> languageIds;
29+
30+
@CommandLine.Option(names = {"-e", "--exclude-language"}, descriptionKey = "crowdin.download.exclude-language", paramLabel = "...", order = -2)
31+
protected List<String> excludeLanguageIds;
32+
33+
@CommandLine.Option(names = {"--pseudo"}, descriptionKey = "crowdin.download.pseudo", order = -2)
34+
protected boolean pseudo;
35+
36+
@CommandLine.Option(names = {"--skip-untranslated-strings"}, descriptionKey = "params.skipUntranslatedStrings", order = -2)
37+
protected Boolean skipTranslatedOnly;
38+
39+
@CommandLine.Option(names = {"--skip-untranslated-files"}, descriptionKey = "params.skipUntranslatedFiles", order = -2)
40+
protected Boolean skipUntranslatedFiles;
41+
42+
@CommandLine.Option(names = {"--export-only-approved"}, descriptionKey = "params.exportOnlyApproved", order = -2)
43+
protected Boolean exportApprovedOnly;
44+
45+
@CommandLine.Option(names = {"--keep-archive"}, descriptionKey = "params.keepArchive", order = -2)
46+
protected boolean keepArchive;
47+
48+
@CommandLine.Option(names = {"--all"}, descriptionKey = "crowdin.download.all", order = -2)
49+
protected boolean all;
50+
51+
@CommandLine.Option(names = {"--dryrun"}, descriptionKey = "dryrun")
52+
protected boolean dryrun;
53+
54+
@CommandLine.Option(names = {"--tree"}, descriptionKey = "tree.dryrun")
55+
protected boolean treeView;
56+
57+
@CommandLine.Option(names = {"--plain"}, descriptionKey = "crowdin.list.usage.plain")
58+
protected boolean plainView;
59+
60+
@Override
61+
protected NewAction<PropertiesWithFiles, ProjectClient> getAction(Actions actions) {
62+
return (dryrun)
63+
? actions.listTranslations(noProgress, treeView, false, plainView, all, true, false)
64+
: actions.download(new FsFiles(), noProgress, languageIds, excludeLanguageIds, pseudo, branchName, ignoreMatch, isVerbose, plainView, all, keepArchive);
65+
}
66+
67+
@Override
68+
protected boolean isAnsi() {
69+
return super.isAnsi() && !plainView;
70+
}
71+
72+
@Override
73+
protected void updateParams(ParamsWithFiles params) {
74+
params.setExportOptions(skipTranslatedOnly, skipUntranslatedFiles, exportApprovedOnly);
75+
}
76+
77+
@Override
78+
protected List<String> checkOptions() {
79+
List<String> errors = new ArrayList<>();
80+
if (languageIds != null && excludeLanguageIds != null) {
81+
errors.add(RESOURCE_BUNDLE.getString("error.download.include_exclude_lang_conflict"));
82+
}
83+
return errors;
84+
}
85+
}

‎src/main/resources/messages/messages.properties

+3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ crowdin.download.exclude-language=Skip the language during download. Can be spec
4747
crowdin.download.pseudo=Download pseudo-localized translation files
4848
crowdin.download.all=Download files even if local sources are missing
4949

50+
crowdin.download.translations.usage.description=Download the latest translations from Crowdin to the specified place
51+
crowdin.download.translations.usage.customSynopsis=@|fg(green) crowdin |@(@|fg(green) download|@|@|fg(green) pull|@) translations [CONFIG OPTIONS] [OPTIONS]
52+
5053
# CROWDIN DOWNLOAD SOURCES COMMAND
5154
crowdin.download.sources.usage.description=Download sources from Crowdin to the specified place
5255
crowdin.download.sources.usage.customSynopsis=@|fg(green) crowdin |@(@|fg(green) download|@|@|fg(green) pull|@) @|fg(green) sources|@ [CONFIG OPTIONS] [OPTIONS]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.crowdin.cli.commands.picocli;
2+
3+
import org.hamcrest.Matchers;
4+
import org.junit.jupiter.api.Test;
5+
6+
import java.util.Arrays;
7+
import java.util.List;
8+
9+
import static com.crowdin.cli.commands.picocli.GenericCommand.RESOURCE_BUNDLE;
10+
import static org.hamcrest.MatcherAssert.assertThat;
11+
import static org.mockito.ArgumentMatchers.any;
12+
import static org.mockito.ArgumentMatchers.anyBoolean;
13+
import static org.mockito.Mockito.verify;
14+
15+
class DownloadTranslationsSubcommandTest extends PicocliTestUtils {
16+
17+
@Test
18+
public void testDownload() {
19+
this.execute(CommandNames.DOWNLOAD, CommandNames.TRANSLATIONS, "--debug");
20+
verify(actionsMock)
21+
.download(any(), anyBoolean(), any(), any(), anyBoolean(), any(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean());
22+
this.check(true);
23+
}
24+
25+
@Test
26+
public void testDownloadDryrun() {
27+
this.execute(CommandNames.DOWNLOAD, CommandNames.TRANSLATIONS, "--dryrun");
28+
verify(actionsMock)
29+
.listTranslations(anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean());
30+
this.check(true);
31+
}
32+
33+
@Test
34+
public void testSubCommandCheckInvalidOptions() {
35+
DownloadTranslationsSubcommand downloadSubcommand = new DownloadTranslationsSubcommand();
36+
downloadSubcommand.languageIds = Arrays.asList("uk", "es-ES");
37+
downloadSubcommand.excludeLanguageIds = Arrays.asList("en");
38+
List<String> errors = downloadSubcommand.checkOptions();
39+
assertThat(errors, Matchers.equalTo(Arrays.asList(RESOURCE_BUNDLE.getString("error.download.include_exclude_lang_conflict"))));
40+
}
41+
}

‎website/mantemplates/crowdin-download-translations.adoc

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
:includedir: ../generated-picocli-docs
2-
:command: crowdin-download
2+
:command: crowdin-download-translations
33

44
== crowdin download translations
55

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

2626
----
27-
crowdin download -l de -l fr -l it
28-
crowdin download --language=de --language=fr --language=it
27+
crowdin download translations -l de -l fr -l it
28+
crowdin download translations --language=de --language=fr --language=it
2929
----
3030

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

3333
----
34-
crowdin download --all
34+
crowdin download translations --all
3535
----

0 commit comments

Comments
 (0)
Please sign in to comment.