Skip to content

Commit

Permalink
feat: language list updates
Browse files Browse the repository at this point in the history
  • Loading branch information
yevheniyJ committed Mar 20, 2024
1 parent ed16a2e commit d4241e1
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public NewAction<PropertiesWithFiles, ProjectClient> listTranslations(

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
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 noProgress;
private boolean plainView;

public ListLanguagesAction(BaseCli.LanguageCode code, boolean noProgress, boolean plainView) {
public LanguageListAction(BaseCli.LanguageCode code, boolean noProgress, boolean plainView) {
this.code = code;
this.noProgress = noProgress || plainView;
this.plainView = plainView;
Expand All @@ -49,7 +49,7 @@ public void act(Outputter out, ProjectProperties properties, ProjectClient clien
LanguageMapping langMapping = project.getLanguageMapping();
if (!plainView) {
project.getProjectLanguages(true).stream()
.map(lang -> String.format(RESOURCE_BUNDLE.getString("message.description"), lang.getName(), this.getCode(langMapping, lang)))
.map(lang -> String.format(RESOURCE_BUNDLE.getString("message.language.list"), this.getCode(langMapping, lang), lang.getName()))
.map(OK::withIcon)
.forEach(out::println);
} else {
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,10 +8,10 @@
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;
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
18 changes: 11 additions & 7 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,15 @@ 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 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 +661,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,6 +669,7 @@ 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.language.list=@|yellow '%s'|@ @|green '%s'|@
message.branch.list=@|yellow #%d|@ @|green '%s'|@

message.source_string_uploaded=Source string was 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);
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, 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);
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);
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);
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);
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);
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, 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
16 changes: 16 additions & 0 deletions website/mantemplates/crowdin-language.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
:includedir: ../generated-picocli-docs
:command: crowdin-language

== crowdin language

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

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

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

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

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

include::{includedir}/{command}.adoc[tag=picocli-generated-man-section-footer]
14 changes: 13 additions & 1 deletion website/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ const sidebars = {
collapsible: true,
collapsed: true,
items: [
'commands/crowdin-list-languages',
'commands/crowdin-list-sources',
'commands/crowdin-list-translations',
'commands/crowdin-list-project',
Expand All @@ -101,6 +100,19 @@ const sidebars = {
'commands/crowdin-branch-delete',
]
},
{
type: 'category',
label: 'crowdin language',
link: {
type: 'doc',
id: 'commands/crowdin-language'
},
collapsible: true,
collapsed: true,
items: [
'commands/crowdin-language-list',
]
},
{
type: 'category',
label: 'crowdin status',
Expand Down

0 comments on commit d4241e1

Please sign in to comment.