Skip to content

Commit

Permalink
feat: fixed option description and handling of invalid labels
Browse files Browse the repository at this point in the history
  • Loading branch information
debanjanc01 committed Oct 5, 2023
1 parent b6c0ea7 commit f131fa2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

import static com.crowdin.cli.BaseCli.RESOURCE_BUNDLE;
Expand Down Expand Up @@ -74,7 +75,7 @@ public void act(Outputter out, PropertiesWithFiles properties, ProjectClient cli

List<String> languages = this.prepareLanguageIds(project);
List<Long> fileIds = this.prepareFileIds(out, properties, project);
List<Long> labelIds = this.prepareLabelIds(client);
List<Long> labelIds = this.prepareLabelIds(out, client);

Check warning on line 78 in src/main/java/com/crowdin/cli/commands/actions/PreTranslateAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/crowdin/cli/commands/actions/PreTranslateAction.java#L78

Added line #L78 was not covered by tests

if (fileIds == null || fileIds.isEmpty()) {
throw new RuntimeException(String.format(RESOURCE_BUNDLE.getString("error.no_files_found_for_pre_translate")));
Expand Down Expand Up @@ -145,15 +146,21 @@ private List<Long> prepareFileIds(Outputter out, PropertiesWithFiles pb, Crowdin
.collect(Collectors.toList());
}

private List<Long> prepareLabelIds(ProjectClient client) {
private List<Long> prepareLabelIds(Outputter out, ProjectClient client) {
if (labelNames != null && !labelNames.isEmpty()) {
Map<String, Long> labels = client.listLabels().stream()
.collect(Collectors.toMap(Label::getTitle, Label::getId));
labelNames.stream()
.distinct()
.forEach(labelName -> labels.computeIfAbsent(labelName, (title) -> client.addLabel(RequestBuilder.addLabel(title)).getId()));
.forEach(labelName -> {

Check warning on line 155 in src/main/java/com/crowdin/cli/commands/actions/PreTranslateAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/crowdin/cli/commands/actions/PreTranslateAction.java#L151-L155

Added lines #L151 - L155 were not covered by tests
if (!labels.containsKey(labelName)) {
out.println(WARNING.withIcon(String.format(RESOURCE_BUNDLE.getString("message.pre_translate.missing_label"), labelName)));

Check warning on line 157 in src/main/java/com/crowdin/cli/commands/actions/PreTranslateAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/crowdin/cli/commands/actions/PreTranslateAction.java#L157

Added line #L157 was not covered by tests
}
}

Check warning on line 159 in src/main/java/com/crowdin/cli/commands/actions/PreTranslateAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/crowdin/cli/commands/actions/PreTranslateAction.java#L159

Added line #L159 was not covered by tests
);
return labelNames.stream()
.map(labels::get)
.filter(Objects::nonNull)
.collect(Collectors.toList());

Check warning on line 164 in src/main/java/com/crowdin/cli/commands/actions/PreTranslateAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/crowdin/cli/commands/actions/PreTranslateAction.java#L161-L164

Added lines #L161 - L164 were not covered by tests
} else {
return null;

Check warning on line 166 in src/main/java/com/crowdin/cli/commands/actions/PreTranslateAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/crowdin/cli/commands/actions/PreTranslateAction.java#L166

Added line #L166 was not covered by tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class PreTranslateSubcommand extends ActCommandWithFiles {
@CommandLine.Option(names = {"--plain"}, descriptionKey = "crowdin.list.usage.plain")
protected boolean plainView;

@CommandLine.Option(names = {"--label"}, descriptionKey = "params.label", paramLabel = "...", order = -2)
@CommandLine.Option(names = {"--label"}, descriptionKey = "crowdin.pre-translate.label", paramLabel = "...", order = -2)
protected List<String> labelNames;

private final Map<String, AutoApproveOption> autoApproveOptionWrapper = new HashMap<String, AutoApproveOption>() {{
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/messages/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ crowdin.pre-translate.auto-approve-option=Defines which translations added by TM
crowdin.pre-translate.duplicate-translations=Adds translations even if the same translation already exists
crowdin.pre-translate.translate-untranslated-only=Applies pre-translation for untranslated strings only
crowdin.pre-translate.translate-with-perfect-match-only=Applies pre-translation only for the strings with perfect match
crowdin.pre-translate.label=Label identifier. Could be specified multiple times

# CROWDIN DISTRIBUTION COMMAND
crowdin.distribution.usage.description=Manage distributions in a Crowdin Project
Expand Down Expand Up @@ -671,6 +672,7 @@ message.comment.added=@|green Comment|@ @|yellow #%s|@ @|green,bold '%s'|@ @|gre

message.pre_translate.local_files_message=Out of %d files, only %d of them were found locally. Use '--verbose' to list them
message.pre_translate.local_files_message_verbose=Out of %d files, %d of them were found locally:
message.pre_translate.missing_label=Label '%s' passed is invalid. Skipping it

message.delete_obsolete.obsolete_file_delete=Obsolete file @|bold '%s'|@ was deleted
message.delete_obsolete.obsolete_directory_delete=No obsolete files were found
Expand Down

0 comments on commit f131fa2

Please sign in to comment.