Skip to content

Commit

Permalink
Add parameter to allow skipping of plurals in comment checker
Browse files Browse the repository at this point in the history
  • Loading branch information
maallen authored and aurambaj committed Aug 1, 2023
1 parent 1b4051a commit c5fbb92
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
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());
}
}

0 comments on commit c5fbb92

Please sign in to comment.