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

Add parameter to allow skipping of plurals in comment checker #974

Merged
merged 1 commit into from
Aug 1, 2023
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.box.l10n.mojito.cli.command.checks;

import static com.box.l10n.mojito.cli.command.checks.CliCheckerParameters.CONTEXT_COMMENT_PLURAL_SKIP;
import static com.box.l10n.mojito.cli.command.checks.CliCheckerParameters.CONTEXT_COMMENT_REJECT_PATTERN_KEY;
import static com.box.l10n.mojito.cli.command.checks.CliCheckerParameters.DICTIONARY_ADDITIONS_PATH_KEY;
import static com.box.l10n.mojito.cli.command.checks.CliCheckerParameters.DICTIONARY_AFFIX_FILE_PATH_KEY;
Expand Down Expand Up @@ -58,6 +59,10 @@ public String getRecommendStringIdLabelIgnorePattern() {
return optionsMap.get(RECOMMEND_STRING_ID_LABEL_IGNORE_PATTERN_KEY.getKey());
}

public Boolean getPluralsSkipped() {
return Boolean.valueOf(optionsMap.get(CONTEXT_COMMENT_PLURAL_SKIP.getKey()));
}

public ImmutableMap<String, String> getOptionsMap() {
return optionsMap;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ public enum CliCheckerParameters {
DICTIONARY_FILE_PATH_KEY("dictionaryFilePath"),
DICTIONARY_AFFIX_FILE_PATH_KEY("dictionaryAffixFilePath"),
CONTEXT_COMMENT_REJECT_PATTERN_KEY("contextCommentRejectPattern"),
RECOMMEND_STRING_ID_LABEL_IGNORE_PATTERN_KEY("recommendStringIdLabelIgnorePattern");
RECOMMEND_STRING_ID_LABEL_IGNORE_PATTERN_KEY("recommendStringIdLabelIgnorePattern"),
CONTEXT_COMMENT_PLURAL_SKIP("contextCommentSkipPlurals");

private String key;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import com.box.l10n.mojito.cli.command.extraction.AssetExtractionDiff;
import com.box.l10n.mojito.okapi.extractor.AssetExtractorTextUnit;
import com.google.common.base.Strings;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -106,6 +107,9 @@ private String checkTextUnit(AssetExtractorTextUnit assetExtractorTextUnit) {
String failureText = null;
String[] splitNameArray = assetExtractorTextUnit.getName().split("---");
String context = null;
if (isPlural(assetExtractorTextUnit) && cliCheckerOptions.getPluralsSkipped()) {
return failureText;
}
if (splitNameArray.length > 1) {
context = splitNameArray[1];
}
Expand All @@ -126,6 +130,10 @@ private String checkTextUnit(AssetExtractorTextUnit assetExtractorTextUnit) {
return failureText;
}

private boolean isPlural(AssetExtractorTextUnit assetExtractorTextUnit) {
return !Strings.isNullOrEmpty(assetExtractorTextUnit.getPluralForm());
}

private boolean isBlank(String string) {
return StringUtils.isBlank(string);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,25 @@ public void testStringsOnlyContainingWhitespace() {
+ System.lineSeparator(),
result.getNotificationText());
}

@Test
public void testPluralStringsSkippedIfOptionEnabled() {
List<AssetExtractorTextUnit> addedTUs = new ArrayList<>();
AssetExtractorTextUnit assetExtractorTextUnit = new AssetExtractorTextUnit();
assetExtractorTextUnit.setName("Some string id --- ");
assetExtractorTextUnit.setSource("A source string with no errors.");
assetExtractorTextUnit.setComments(null);
assetExtractorTextUnit.setPluralForm("one");
addedTUs.add(assetExtractorTextUnit);
List<AssetExtractionDiff> assetExtractionDiffs = new ArrayList<>();
AssetExtractionDiff assetExtractionDiff = new AssetExtractionDiff();
assetExtractionDiff.setAddedTextunits(addedTUs);
assetExtractionDiffs.add(assetExtractionDiff);
ImmutableMap<String, String> optionsMap =
ImmutableMap.of(CliCheckerParameters.CONTEXT_COMMENT_PLURAL_SKIP.getKey(), "true");
contextAndCommentCliChecker.setCliCheckerOptions(
new CliCheckerOptions(Sets.newHashSet(SINGLE_BRACE_REGEX), Sets.newHashSet(), optionsMap));
CliCheckResult result = contextAndCommentCliChecker.run(assetExtractionDiffs);
Assert.assertTrue(result.isSuccessful());
}
}
Loading