Skip to content

Commit

Permalink
check
Browse files Browse the repository at this point in the history
  • Loading branch information
katerina20 committed Jan 31, 2024
1 parent da9bd10 commit 1723c5e
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 27 deletions.
12 changes: 5 additions & 7 deletions src/main/java/com/crowdin/cli/commands/Actions.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
import com.crowdin.cli.BaseCli;
import com.crowdin.cli.client.*;
import com.crowdin.cli.commands.functionality.FilesInterface;
import com.crowdin.cli.properties.BaseProperties;
import com.crowdin.cli.properties.ProjectProperties;
import com.crowdin.cli.properties.NoProperties;
import com.crowdin.cli.properties.PropertiesWithTargets;
import com.crowdin.cli.properties.PropertiesWithFiles;
import com.crowdin.cli.commands.picocli.ConfigurationFilesProperties;
import com.crowdin.cli.properties.*;
import com.crowdin.client.core.model.Priority;
import com.crowdin.client.distributions.model.ExportMode;
import com.crowdin.client.glossaries.model.GlossariesFormat;
Expand Down Expand Up @@ -113,9 +110,10 @@ NewAction<PropertiesWithTargets, ProjectClient> downloadTargets(

NewAction<NoProperties, NoClient> checkNewVersion();

NewAction<PropertiesWithFiles, ProjectClient> preTranslate(
NewAction<ProjectProperties, ProjectClient> preTranslate(
List<String> languageIds, Method method, Long engineId, String branchName, AutoApproveOption autoApproveOption, Boolean duplicateTranslations,
Boolean translateUntranslatedOnly, Boolean translateWithPerfectMatchOnly, boolean noProgress, boolean debug, boolean verbose, boolean plainView, List<String> labelNames);
Boolean translateUntranslatedOnly, Boolean translateWithPerfectMatchOnly, boolean noProgress, boolean debug, boolean verbose, boolean plainView,
List<String> labelNames, ParamsWithFiles paramsWithFiles, ConfigurationFilesProperties configurationFilesProperties);

NewAction<ProjectProperties, ProjectClient> branchAdd(String name, String title, String exportPattern, Priority priority);

Expand Down
14 changes: 6 additions & 8 deletions src/main/java/com/crowdin/cli/commands/actions/CliActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
import com.crowdin.cli.commands.Actions;
import com.crowdin.cli.commands.NewAction;
import com.crowdin.cli.commands.functionality.FilesInterface;
import com.crowdin.cli.properties.BaseProperties;
import com.crowdin.cli.properties.ProjectProperties;
import com.crowdin.cli.properties.NoProperties;
import com.crowdin.cli.properties.PropertiesWithTargets;
import com.crowdin.cli.properties.PropertiesWithFiles;
import com.crowdin.cli.commands.picocli.ConfigurationFilesProperties;
import com.crowdin.cli.properties.*;
import com.crowdin.client.core.model.Priority;
import com.crowdin.client.distributions.model.ExportMode;
import com.crowdin.client.glossaries.model.GlossariesFormat;
Expand Down Expand Up @@ -229,12 +226,13 @@ public NewAction<PropertiesWithTargets, ProjectClient> downloadTargets(
}

@Override
public NewAction<PropertiesWithFiles, ProjectClient> preTranslate(
public NewAction<ProjectProperties, ProjectClient> preTranslate(
List<String> languageIds, Method method, Long engineId, String branchName, AutoApproveOption autoApproveOption, Boolean duplicateTranslations,
Boolean translateUntranslatedOnly, Boolean translateWithPerfectMatchOnly, boolean noProgress, boolean debug, boolean verbose, boolean plainView, List<String> labelNames
Boolean translateUntranslatedOnly, Boolean translateWithPerfectMatchOnly, boolean noProgress, boolean debug, boolean verbose, boolean plainView,
List<String> labelNames, ParamsWithFiles paramsWithFiles, ConfigurationFilesProperties configurationFilesProperties
) {
return new PreTranslateAction(languageIds, method, engineId, branchName, autoApproveOption, duplicateTranslations,
translateUntranslatedOnly, translateWithPerfectMatchOnly, noProgress, debug, verbose, plainView, labelNames);
translateUntranslatedOnly, translateWithPerfectMatchOnly, noProgress, debug, verbose, plainView, labelNames, paramsWithFiles, configurationFilesProperties);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@
import com.crowdin.cli.client.ProjectClient;
import com.crowdin.cli.commands.NewAction;
import com.crowdin.cli.commands.Outputter;
import com.crowdin.cli.commands.functionality.*;
import com.crowdin.cli.commands.functionality.ProjectFilesUtils;
import com.crowdin.cli.commands.functionality.PropertiesBeanUtils;
import com.crowdin.cli.commands.functionality.RequestBuilder;
import com.crowdin.cli.commands.functionality.SourcesUtils;
import com.crowdin.cli.commands.picocli.ConfigurationFilesProperties;
import com.crowdin.cli.properties.ParamsWithFiles;
import com.crowdin.cli.properties.ProjectProperties;
import com.crowdin.cli.properties.PropertiesBuilders;
import com.crowdin.cli.properties.PropertiesWithFiles;
import com.crowdin.cli.utils.PlaceholderUtil;
import com.crowdin.cli.utils.Utils;
Expand All @@ -26,7 +33,7 @@
import static com.crowdin.cli.BaseCli.RESOURCE_BUNDLE;
import static com.crowdin.cli.utils.console.ExecutionStatus.WARNING;

class PreTranslateAction implements NewAction<PropertiesWithFiles, ProjectClient> {
class PreTranslateAction implements NewAction<ProjectProperties, ProjectClient> {

private List<String> languageIds;
private Method method;
Expand All @@ -42,9 +49,13 @@ class PreTranslateAction implements NewAction<PropertiesWithFiles, ProjectClient
private boolean plainView;
private List<String> labelNames;

private ParamsWithFiles paramsWithFiles;
private ConfigurationFilesProperties configurationFilesProperties;

public PreTranslateAction(
List<String> languageIds, Method method, Long engineId, String branchName, AutoApproveOption autoApproveOption, Boolean duplicateTranslations,
Boolean translateUntranslatedOnly, Boolean translateWithPerfectMatchOnly, boolean noProgress, boolean debug, boolean verbose, boolean plainView, List<String> labelNames
Boolean translateUntranslatedOnly, Boolean translateWithPerfectMatchOnly, boolean noProgress, boolean debug, boolean verbose, boolean plainView,
List<String> labelNames, ParamsWithFiles paramsWithFiles, ConfigurationFilesProperties configurationFilesProperties
) {
this.languageIds = languageIds;
this.method = method;
Expand All @@ -59,10 +70,12 @@ public PreTranslateAction(
this.verbose = verbose;
this.plainView = plainView;
this.labelNames = labelNames;
this.paramsWithFiles = paramsWithFiles;
this.configurationFilesProperties = configurationFilesProperties;
}

@Override
public void act(Outputter out, PropertiesWithFiles properties, ProjectClient client) {
public void act(Outputter out, ProjectProperties properties, ProjectClient client) {
CrowdinProjectFull project = ConsoleSpinner.execute(out, "message.spinner.fetching_project_info", "error.collect_project_info",
this.noProgress, this.plainView, () -> client.downloadFullProject(this.branchName));

Expand Down Expand Up @@ -107,15 +120,17 @@ private List<String> prepareLanguageIds(CrowdinProjectInfo projectInfo) {
}
}

private List<Long> prepareFileIds(Outputter out, PropertiesWithFiles pb, CrowdinProjectFull project) {
private List<Long> prepareFileIds(Outputter out, ProjectProperties pb, CrowdinProjectFull project) {
PropertiesWithFiles propertiesWithFiles = getPropertiesWithFiles(out);

Map<String, FileInfo> paths = ProjectFilesUtils.buildFilePaths(project.getDirectories(), project.getBranches(), project.getFileInfos());
PlaceholderUtil placeholderUtil = new PlaceholderUtil(project.getSupportedLanguages(), project.getProjectLanguages(false), pb.getBasePath());
List<String> sourcePaths = pb.getFiles().stream()
List<String> sourcePaths = propertiesWithFiles.getFiles().stream()
.flatMap(file -> {
List<String> sources = SourcesUtils.getFiles(pb.getBasePath(), file.getSource(), file.getIgnore(), placeholderUtil)
.map(File::getAbsolutePath)
.collect(Collectors.toList());
String commonPath = (pb.getPreserveHierarchy()) ? "" : SourcesUtils.getCommonPath(sources, pb.getBasePath());
String commonPath = (propertiesWithFiles.getPreserveHierarchy()) ? "" : SourcesUtils.getCommonPath(sources, pb.getBasePath());
return sources.stream()
.map(source -> (file.getDest() != null)
? PropertiesBeanUtils.prepareDest(file.getDest(), StringUtils.removeStart(source, pb.getBasePath()), placeholderUtil) : StringUtils.removeStart(source, pb.getBasePath() + commonPath))
Expand Down Expand Up @@ -146,6 +161,11 @@ private List<Long> prepareFileIds(Outputter out, PropertiesWithFiles pb, Crowdin
.collect(Collectors.toList());
}

private PropertiesWithFiles getPropertiesWithFiles (Outputter out) {
PropertiesBuilders builders = new PropertiesBuilders();
return builders.buildPropertiesWithFiles(out, configurationFilesProperties.getConfigFile(), configurationFilesProperties.getIdentityFile(), paramsWithFiles);
}

private List<Long> prepareLabelIds(Outputter out, ProjectClient client) {
if (labelNames != null && !labelNames.isEmpty()) {
Map<String, Long> labels = client.listLabels().stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public abstract class ActCommandProject extends GenericActCommand<ProjectProperties, ProjectClient> {

@CommandLine.Mixin
private ConfigurationFilesProperties properties;
protected ConfigurationFilesProperties properties;

@CommandLine.ArgGroup(exclusive = false, headingKey = "params.heading")
private ProjectParams params;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import com.crowdin.cli.client.ProjectClient;
import com.crowdin.cli.commands.Actions;
import com.crowdin.cli.commands.NewAction;
import com.crowdin.cli.properties.PropertiesWithFiles;
import com.crowdin.cli.properties.ParamsWithFiles;
import com.crowdin.cli.properties.ProjectProperties;
import com.crowdin.client.translations.model.AutoApproveOption;
import com.crowdin.client.translations.model.Method;
import picocli.CommandLine;
Expand All @@ -20,7 +21,7 @@
name = CommandNames.PRE_TRANSLATE,
sortOptions = false
)
public class PreTranslateSubcommand extends ActCommandWithFiles {
public class PreTranslateSubcommand extends ActCommandProject {

@CommandLine.Option(names = {"-l", "--language"}, paramLabel = "...", defaultValue = BaseCli.ALL, order = -2)
protected List<String> languageIds;
Expand Down Expand Up @@ -52,6 +53,12 @@ public class PreTranslateSubcommand extends ActCommandWithFiles {
@CommandLine.Option(names = {"--label"}, descriptionKey = "crowdin.pre-translate.label", paramLabel = "...", order = -2)
protected List<String> labelNames;

@CommandLine.ArgGroup(exclusive = false, headingKey = "params.heading")
private ParamsWithFiles params;

@CommandLine.Mixin
private ConfigurationFilesProperties properties;

private final Map<String, AutoApproveOption> autoApproveOptionWrapper = new HashMap<String, AutoApproveOption>() {{
put("all", AutoApproveOption.ALL);
put("except-auto-substituted", AutoApproveOption.EXCEPT_AUTO_SUBSTITUTED);
Expand All @@ -65,7 +72,7 @@ protected final boolean isAnsi() {
}

@Override
protected NewAction<PropertiesWithFiles, ProjectClient> getAction(Actions actions) {
protected NewAction<ProjectProperties, ProjectClient> getAction(Actions actions) {
return actions.preTranslate(
languageIds,
method,
Expand All @@ -79,7 +86,9 @@ protected NewAction<PropertiesWithFiles, ProjectClient> getAction(Actions action
debug,
isVerbose,
plainView,
labelNames
labelNames,
params,
properties
);
}

Expand Down

0 comments on commit 1723c5e

Please sign in to comment.