Skip to content

Commit

Permalink
Add option to override translation status during import
Browse files Browse the repository at this point in the history
Currently, if the target has not changed, we retain the status to ensure that a false positive "rejected" string can be marked as "accepted."

However, this approach has a drawback: if a new integrity check is added that would cause a failure, the strings remain marked as "accepted" rather than being updated to "rejected."

We are adding this option to allow for a complete re-application of the checks. The downside is that any false positives will need to be re-marked as "accepted."
  • Loading branch information
ja-openai committed Aug 27, 2024
1 parent 6a77520 commit 2c3fe65
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
10 changes: 10 additions & 0 deletions common/src/main/java/com/box/l10n/mojito/utils/OptionsParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ public void getBoolean(String key, Consumer<Boolean> consumer) {
}
}

public Boolean getBoolean(String key) {
Boolean value = null;

if (this.options.containsKey(key)) {
value = Boolean.valueOf(this.options.get(key));
}

return value;
}

public void getInteger(String key, Consumer<Integer> consumer) {
if (this.options.containsKey(key)) {
consumer.accept(Integer.valueOf(this.options.get(key)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.box.l10n.mojito.service.tm.search.TextUnitSearcher;
import com.box.l10n.mojito.service.tm.search.TextUnitSearcherParameters;
import com.box.l10n.mojito.service.tm.search.UsedFilter;
import com.box.l10n.mojito.utils.OptionsParser;
import com.google.common.base.Stopwatch;
import com.google.common.collect.ImmutableList;
import com.phrase.client.model.Tag;
Expand Down Expand Up @@ -292,36 +293,39 @@ public PollableFuture<Void> pull(

String currentTags = getCurrentTagsForRepository(repository, projectId);

OptionsParser optionsParser = new OptionsParser(optionList);
Boolean integrityCheckKeepStatusIfFailedAndSameTarget = optionsParser.getBoolean("integrityCheckKeepStatusIfFailedAndSameTarget");

// may already hit rate limit, according it is 4 qps ... there is a retry in the locale client
// though.
// but 4 qps is very low to download 64 locales.
repositoryLocalesWithoutRootLocale.parallelStream()
.forEach(
locale -> pullLocaleTimed(repository, projectId, locale, pluralSeparator, currentTags));
locale -> pullLocaleTimed(repository, projectId, locale, pluralSeparator, currentTags, integrityCheckKeepStatusIfFailedAndSameTarget));

return null;
}

private void pullLocaleTimed(
Repository repository,
String projectId,
RepositoryLocale repositoryLocale,
String pluralSeparator,
String currentTags) {
Repository repository,
String projectId,
RepositoryLocale repositoryLocale,
String pluralSeparator,
String currentTags, boolean integrityCheckKeepStatusIfFailedAndSameTarget) {
try (var timer =
Timer.resource(meterRegistry, "ThirdPartyTMSPhrase.pullLocale")
.tag("repository", repository.getName())) {

pullLocale(repository, projectId, repositoryLocale, pluralSeparator, currentTags);
pullLocale(repository, projectId, repositoryLocale, pluralSeparator, currentTags, integrityCheckKeepStatusIfFailedAndSameTarget);
}
}

private void pullLocale(
Repository repository,
String projectId,
RepositoryLocale repositoryLocale,
String pluralSeparator,
String currentTags) {
Repository repository,
String projectId,
RepositoryLocale repositoryLocale,
String pluralSeparator,
String currentTags, boolean integrityCheckKeepStatusIfFailedAndSameTarget) {

String localeTag = repositoryLocale.getLocale().getBcp47Tag();
logger.info("Downloading locale: {} from Phrase with tags: {}", localeTag, currentTags);
Expand Down Expand Up @@ -352,7 +356,7 @@ private void pullLocale(
textUnitDTOS.forEach(t -> t.setComment(null));

Stopwatch importStopWatch = Stopwatch.createStarted();
textUnitBatchImporterService.importTextUnits(textUnitDTOS, false, true);
textUnitBatchImporterService.importTextUnits(textUnitDTOS, false, integrityCheckKeepStatusIfFailedAndSameTarget); // TODO(ja) can this be made an option?
logger.info("Time importing text units: {}", importStopWatch.elapsed());
}

Expand Down

0 comments on commit 2c3fe65

Please sign in to comment.