Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: language list updates #744

Merged
merged 3 commits into from
Mar 21, 2024
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
10 changes: 8 additions & 2 deletions src/main/java/com/crowdin/cli/client/CrowdinProjectClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.crowdin.client.core.model.PatchRequest;
import com.crowdin.client.labels.model.AddLabelRequest;
import com.crowdin.client.labels.model.Label;
import com.crowdin.client.languages.model.Language;
import com.crowdin.client.projectsgroups.model.ProjectSettings;
import com.crowdin.client.projectsgroups.model.Type;
import com.crowdin.client.sourcefiles.model.*;
Expand Down Expand Up @@ -31,6 +32,12 @@ public CrowdinProjectClient(com.crowdin.client.Client client, long projectId) {
this.projectId = projectId;
}

@Override
public List<Language> listSupportedLanguages() {
return executeRequestFullList((limit, offset) -> this.client.getLanguagesApi()
.listSupportedLanguages(limit, offset));
}

@Override
public CrowdinProjectFull downloadFullProject(String branchName) {
CrowdinProjectFull project = new CrowdinProjectFull();
Expand Down Expand Up @@ -75,8 +82,7 @@ private void populateProjectWithStructure(CrowdinProjectFull project, String bra
}

private void populateProjectWithLangs(CrowdinProject project) {
project.setSupportedLanguages(executeRequestFullList((limit, offset) -> this.client.getLanguagesApi()
.listSupportedLanguages(limit, offset)));
project.setSupportedLanguages(this.listSupportedLanguages());
}

private void populateProjectWithInfo(CrowdinProjectInfo project) {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/crowdin/cli/client/ProjectClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.crowdin.client.distributions.model.DistributionRelease;
import com.crowdin.client.labels.model.AddLabelRequest;
import com.crowdin.client.labels.model.Label;
import com.crowdin.client.languages.model.Language;
import com.crowdin.client.sourcefiles.model.*;
import com.crowdin.client.sourcestrings.model.*;
import com.crowdin.client.stringcomments.model.AddStringCommentRequest;
Expand All @@ -22,6 +23,8 @@ default CrowdinProjectFull downloadFullProject() {
return this.downloadFullProject(null);
}

List<Language> listSupportedLanguages();

CrowdinProjectFull downloadFullProject(String branchName);

CrowdinProject downloadProjectWithLanguages();
Expand Down
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 @@ -42,7 +42,7 @@ NewAction<PropertiesWithFiles, ProjectClient> listSources(
NewAction<PropertiesWithFiles, ProjectClient> listTranslations(
boolean noProgress, boolean treeView, boolean isLocal, boolean plainView, boolean useServerSources, boolean withInContextLang);

NewAction<ProjectProperties, ProjectClient> listLanguages(BaseCli.LanguageCode code, boolean noProgress, boolean plainView);
NewAction<ProjectProperties, ProjectClient> listLanguages(BaseCli.LanguageCode code, boolean all, boolean noProgress, boolean plainView);

NewAction<ProjectProperties, ProjectClient> status(
boolean noProgress, String branchName, String languageId, String file, String directory, boolean isVerbose, boolean showTranslated, boolean showApproved, boolean failIfIncomplete);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public NewAction<PropertiesWithFiles, ProjectClient> listTranslations(
}

@Override
public NewAction<ProjectProperties, ProjectClient> listLanguages(BaseCli.LanguageCode code, boolean noProgress, boolean plainView) {
return new ListLanguagesAction(code, noProgress, plainView);
public NewAction<ProjectProperties, ProjectClient> listLanguages(BaseCli.LanguageCode code, boolean all, boolean noProgress, boolean plainView) {
return new LanguageListAction(code, all, noProgress, plainView);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.crowdin.cli.utils.console.ConsoleSpinner;
import com.crowdin.client.languages.model.Language;

import java.util.List;

import static com.crowdin.cli.BaseCli.RESOURCE_BUNDLE;
import static com.crowdin.cli.utils.PlaceholderUtil.PLACEHOLDER_ANDROID_CODE;
import static com.crowdin.cli.utils.PlaceholderUtil.PLACEHOLDER_LOCALE;
Expand All @@ -20,14 +22,16 @@
import static com.crowdin.cli.utils.console.ExecutionStatus.OK;
import static com.crowdin.cli.utils.console.ExecutionStatus.WARNING;

class ListLanguagesAction implements NewAction<ProjectProperties, ProjectClient> {
class LanguageListAction implements NewAction<ProjectProperties, ProjectClient> {

private BaseCli.LanguageCode code;
private boolean all;
private boolean noProgress;
private boolean plainView;

public ListLanguagesAction(BaseCli.LanguageCode code, boolean noProgress, boolean plainView) {
public LanguageListAction(BaseCli.LanguageCode code, boolean all, boolean noProgress, boolean plainView) {
this.code = code;
this.all = all;
this.noProgress = noProgress || plainView;
this.plainView = plainView;
}
Expand All @@ -47,13 +51,15 @@ public void act(Outputter out, ProjectProperties properties, ProjectClient clien
}

LanguageMapping langMapping = project.getLanguageMapping();
List<Language> languages = this.all ? client.listSupportedLanguages() : project.getProjectLanguages(true);

if (!plainView) {
project.getProjectLanguages(true).stream()
.map(lang -> String.format(RESOURCE_BUNDLE.getString("message.description"), lang.getName(), this.getCode(langMapping, lang)))
languages.stream()
.map(lang -> String.format(RESOURCE_BUNDLE.getString("message.language.list"), this.getCode(langMapping, lang), lang.getName()))
.map(OK::withIcon)
.forEach(out::println);
} else {
project.getProjectLanguages(true).stream()
languages.stream()
.map(lang -> this.getCode(langMapping, lang))
.forEach(out::println);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public final class CommandNames {
public static final String LIST_PROJECT = "project";
public static final String LIST_SOURCES = "sources";
public static final String LIST_TRANSLATIONS = "translations";
public static final String LIST_LANGUAGES = "languages";

public static final String STATUS = "status";
public static final String STATUS_TRANSLATION = "translation";
Expand Down Expand Up @@ -74,4 +73,5 @@ public final class CommandNames {
public static final String FILE_UPLOAD = "upload";
public static final String FILE_DOWNLOAD = "download";
public static final String FILE_DELETE = "delete";
public static final String LANGUAGE = "language";
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,23 @@
import picocli.CommandLine;

@CommandLine.Command(
name = CommandNames.LIST_LANGUAGES,
name = CommandNames.LIST,
sortOptions = false
)
class ListLanguagesSubcommand extends ActCommandProject {
class LanguageListSubcommand extends ActCommandProject {

@CommandLine.Option(names = {"--code"}, paramLabel = "...", order = -2)
protected BaseCli.LanguageCode code;

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

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

@Override
protected NewAction<ProjectProperties, ProjectClient> getAction(Actions actions) {
return actions.listLanguages(code, noProgress, plainView);
return actions.listLanguages(code, all, noProgress, plainView);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.crowdin.cli.commands.picocli;

import picocli.CommandLine;

@CommandLine.Command(
name = CommandNames.LANGUAGE,
subcommands = {
LanguageListSubcommand.class
}
)
class LanguageSubcommand extends HelpCommand {
@Override
protected CommandLine getCommand(CommandLine rootCommand) {
return rootCommand.getSubcommands().get(CommandNames.LANGUAGE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
subcommands = {
ListProjectSubcommand.class,
ListSourcesSubcommand.class,
ListTranslationsSubcommand.class,
ListLanguagesSubcommand.class
ListTranslationsSubcommand.class
})
class ListSubcommand extends HelpCommand {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
ScreenshotSubcommand.class,
LabelSubcommand.class,
FileSubcommand.class,
LanguageSubcommand.class
})
class RootCommand extends HelpCommand {
@Override
Expand Down
31 changes: 18 additions & 13 deletions src/main/resources/messages/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,13 @@ crowdin.list.sources.usage.description=List information about the source files t
crowdin.list.sources.usage.customSynopsis=@|fg(green) crowdin list sources|@ [CONFIG OPTIONS] [OPTIONS]

# CROWDIN LIST COMMAND
crowdin.list.usage.description=Show a list of files or target languages
crowdin.list.usage.description=Show a list of files
crowdin.list.usage.customSynopsis=@|fg(green) crowdin list|@ [SUBCOMMAND] [CONFIG OPTIONS] [OPTIONS]

# CROWDIN LIST TRANSLATIONS COMMAND
crowdin.list.translations.usage.description=List information about the translation files that match the wild-card pattern contained in the current project
crowdin.list.translations.usage.customSynopsis=@|fg(green) crowdin list translations|@ [CONFIG OPTIONS] [OPTIONS]

#CROWDIN LIST LANGUAGES COMMAND
crowdin.list.languages.usage.description=List target languages in the current project
crowdin.list.languages.usage.customSynopsis=@|fg(green) crowdin list languages|@ [CONFIG OPTIONS] [OPTIONS]
crowdin.list.languages.code=Specify language code. Supported values: id, two_letters_code, three_letters_code, locale, android_code, osx_code, osx_locale. Default: two_letters_code

# CROWDIN COMMAND
crowdin.usage.description.0=Crowdin CLI is a command-line tool that allows you to manage and synchronize localization resources with your Crowdin project.
crowdin.usage.description.1=Visit the official documentation for more details: https://crowdin.github.io/crowdin-cli
Expand All @@ -117,6 +112,16 @@ crowdin.upload.translations.auto-approve-imported=Approve added translations aut
crowdin.upload.translations.import-eq-suggestions=Add translations even if they're the same as the source strings in your Crowdin project
crowdin.upload.translations.translate-hidden=Upload translations to hidden source strings

# CROWDIN LANGUAGE COMMAND
crowdin.language.usage.description=Manage languages in a Crowdin project
crowdin.language.usage.customSynopsis=@|fg(green) crowdin language|@ [SUBCOMMAND] [CONFIG OPTIONS] [OPTIONS]

# CROWDIN LANGUAGE LIST COMMAND
crowdin.language.list.usage.description=List target languages in the current project
crowdin.language.list.usage.customSynopsis=@|fg(green) crowdin language list|@ [CONFIG OPTIONS] [OPTIONS]
crowdin.language.list.code=Specify language code. Supported values: id, two_letters_code, three_letters_code, locale, android_code, osx_code, osx_locale. Default: two_letters_code
crowdin.language.list.all=To fetch all languages within account

# CROWDIN FILE COMMAND
crowdin.file.usage.description=Manage source files and translations in a Crowdin project
crowdin.file.usage.customSynopsis=@|fg(green) crowdin file|@ [SUBCOMMAND] [CONFIG OPTIONS] [OPTIONS]
Expand Down Expand Up @@ -657,7 +662,6 @@ message.target_success=@|fg(green),bold '%s'|@ @|fg(green) target successfully d
message.target_deprecated=This command is deprecated. Please use 'crowdin bundle' and 'crowdin download bundle' commands instead
message.no_targets_to_exec=Couldn't find any targets to download
message.no_target_to_exec=Couldn't find @|bold '%s'|@ target to download
message.description=%s @|bold '%s'|@
message.obsolete_file=Obsolete file @|bold '%s'|@
message.file_id_deprecated=File id is deprecated and will be removed in future releases. Please use file path instead
message.file_deleted=File @|bold '%s'|@ deleted
Expand All @@ -666,7 +670,8 @@ message.no_file_string_project=File management is not available for string-based
message.download_sources.preserve_hierarchy_warning=Because the @|bold 'preserve_hierarchy'|@ parameter is set to 'false':\n\t- CLI might download some unexpected files that match the pattern;\n\t- Source file hierarchy may not be preserved and will be the same as in Crowdin.
message.download_translations.preserve_hierarchy_warning=Because the @|bold 'preserve_hierarchy'|@ parameter is set to 'false' CLI might download some unexpected files that match the pattern

message.branch.list=@|yellow #%d|@ @|green '%s'|@
message.language.list=@|yellow %s|@ @|green %s|@
message.branch.list=@|yellow #%d|@ @|green %s|@

message.source_string_uploaded=Source string was added successfully
message.source_string_for_file_uploaded=Source string was added successfully to the file @|bold '%s'|@
Expand All @@ -679,12 +684,12 @@ message.source_string_list_max_length=\t- @|bold max-length|@: %s
message.source_string_list_not_found=No strings found

message.glossary.download_success=@|green,bold '%s'|@ @|green downloaded successfully|@
message.glossary.list=@|yellow #%d|@ @|bold '%s'|@ (@|green terms: %d|@)
message.glossary.list=@|yellow #%d|@ @|bold %s|@ (@|green terms: %d|@)
message.glossary.list_term=\t@|yellow #%d|@ @|cyan '%s'|@: %s
message.glossary.import_success=Imported in @|yellow #%s|@ @|green '%s'|@ glossary

message.tm.download_success=@|green,bold '%s'|@ @|green downloaded successfully|@
message.tm.list=@|yellow #%d|@ @|bold '%s'|@ (@|green segments: %d|@)
message.tm.list=@|yellow #%d|@ @|bold %s|@ (@|green segments: %d|@)
message.tm.import_success=Imported in @|yellow #%s|@ @|green '%s'|@ translation memory
message.tm.list_empty=No translation memories found

Expand All @@ -693,9 +698,9 @@ message.screenshot.updated=@|green,bold Screenshot '%s'|@ @|green updated succes
message.screenshot.deleted=@|green,bold Screenshot '%s'|@ @|green deleted successfully|@
message.screenshot.not_auto-tagged=Tags were not applied for %s because auto tag is currently in progress
message.screenshot.list_empty=No screenshot found
message.screenshot.list=@|yellow #%d|@ @|bold '%s'|@ @|green %d tags|@
message.screenshot.list=@|yellow #%d|@ @|bold %s|@ @|green %d tags|@

message.task.list=@|yellow #%d|@ @|bold %s|@ @|green '%s'|@
message.task.list=@|yellow #%d|@ @|bold %s|@ @|green %s|@
message.task.list.verbose=@|yellow #%d|@ @|bold %s|@ @|green '%s'|@ @|bold %s|@ @|yellow %d|@ @|red %s|@
message.task.list_empty=No tasks found
message.task.added=@|green,bold Task '%s'|@ @|green added successfully|@
Expand All @@ -706,7 +711,7 @@ message.distribution.added=@|green,bold Distribution '%s'|@ @|green added succes
message.distribution.released=@|green,bold Distribution '%s'|@ @|green released successfully|@

message.bundle.download_success=@|yellow #%d|@ @|green,bold '%s'|@ @|green downloaded successfully|@
message.bundle.list=@|yellow #%d|@ @|bold '%s'|@ @|green %s|@ @|red %s|@
message.bundle.list=@|yellow #%d|@ @|bold %s|@ @|green %s|@ @|red %s|@
message.bundle.list_empty=No bundles found
message.bundle.added=@|green,bold Bundle #%s '%s'|@ @|green added successfully|@

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.*;

public class ListLanguagesActionTest {
public class LanguageListActionTest {

ProjectClient client;
CrowdinProjectInfo projectInfo;
Expand Down Expand Up @@ -45,7 +45,7 @@ public String getValueOrDefault(String languageId, String placeholder, String de
@Test
public void testActWithNoManagerAccess() {
when(projectInfo.isManagerAccess()).thenReturn(false);
ListLanguagesAction action = new ListLanguagesAction(BaseCli.LanguageCode.id, false, false);
LanguageListAction action = new LanguageListAction(BaseCli.LanguageCode.id, false, false, false);
action.act(out, properties, client);
verify(out, times(2)).println(anyString());
}
Expand All @@ -58,7 +58,7 @@ public void testActPrintLanguagesPlainView() {
lang.setTwoLettersCode("en");
when(projectInfo.getProjectLanguages(true)).thenReturn(Collections.singletonList(lang));

ListLanguagesAction action = new ListLanguagesAction(BaseCli.LanguageCode.id, false, true);
LanguageListAction action = new LanguageListAction(BaseCli.LanguageCode.id, false, false, true);
action.act(out, properties, client);
verify(out).println("en");
}
Expand All @@ -69,7 +69,7 @@ public void testActPrintLanguagesWithThreeLettersCode() {
lang.setThreeLettersCode("eng");
when(projectInfo.getProjectLanguages(true)).thenReturn(Collections.singletonList(lang));

ListLanguagesAction action = new ListLanguagesAction(BaseCli.LanguageCode.three_letters_code, false, false);
LanguageListAction action = new LanguageListAction(BaseCli.LanguageCode.three_letters_code, false, false, false);
action.act(out, properties, client);
verify(out).println(contains("eng"));
}
Expand All @@ -80,7 +80,7 @@ public void testActPrintLanguagesWithAndroidCode() {
lang.setAndroidCode("en-rUS");
when(projectInfo.getProjectLanguages(true)).thenReturn(Collections.singletonList(lang));

ListLanguagesAction action = new ListLanguagesAction(BaseCli.LanguageCode.android_code, false, false);
LanguageListAction action = new LanguageListAction(BaseCli.LanguageCode.android_code, false, false, false);
action.act(out, properties, client);
verify(out).println(contains("en-rUS"));
}
Expand All @@ -91,7 +91,7 @@ public void testActPrintLanguagesWithOsxCode() {
lang.setOsxCode("en");
when(projectInfo.getProjectLanguages(true)).thenReturn(Collections.singletonList(lang));

ListLanguagesAction action = new ListLanguagesAction(BaseCli.LanguageCode.osx_code, false, false);
LanguageListAction action = new LanguageListAction(BaseCli.LanguageCode.osx_code, false, false, false);
action.act(out, properties, client);
verify(out).println(contains("en"));
}
Expand All @@ -102,7 +102,7 @@ public void testActPrintLanguagesWithOsxLocale() {
lang.setOsxLocale("en_US");
when(projectInfo.getProjectLanguages(true)).thenReturn(Collections.singletonList(lang));

ListLanguagesAction action = new ListLanguagesAction(BaseCli.LanguageCode.osx_locale, false, false);
LanguageListAction action = new LanguageListAction(BaseCli.LanguageCode.osx_locale, false, false, false);
action.act(out, properties, client);
verify(out).println(contains("en_US"));
}
Expand All @@ -113,7 +113,7 @@ public void testActPrintLanguagesWithLocale() {
lang.setLocale("en_US");
when(projectInfo.getProjectLanguages(true)).thenReturn(Collections.singletonList(lang));

ListLanguagesAction action = new ListLanguagesAction(BaseCli.LanguageCode.locale, false, false);
LanguageListAction action = new LanguageListAction(BaseCli.LanguageCode.locale, false, false, false);
action.act(out, properties, client);
verify(out).println(contains("en_US"));
}
Expand All @@ -122,7 +122,7 @@ public void testActPrintLanguagesWithLocale() {
public void testActWithoutManagerAccessPlainView() {
when(projectInfo.isManagerAccess()).thenReturn(false);

ListLanguagesAction action = new ListLanguagesAction(BaseCli.LanguageCode.id, false, true);
LanguageListAction action = new LanguageListAction(BaseCli.LanguageCode.id, false, false, true);
assertThrows(RuntimeException.class, () -> action.act(out, properties, client));
}
}
15 changes: 15 additions & 0 deletions website/docs/releases/migration-4.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,18 @@ Before:
After:

- `crowdin branch list`

### Language updates

* removed `crowdin list languages` command
* create new command `crowdin language list` command
* updated `list` cmd output
* added new param `--all` to get all languages for current account

Before:

- `crowdin list languages`

After:

- `crowdin language list`
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
:includedir: ../generated-picocli-docs
:command: crowdin-list-languages
:command: crowdin-language-list

== crowdin list languages
== crowdin language list

include::{includedir}/{command}.adoc[tag=picocli-generated-man-section-description]

Expand Down
Loading