Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Avoid warning when pushing HTextFlowTarget with state New; add TFT co…
Browse files Browse the repository at this point in the history
…ntents to warning messages
  • Loading branch information
seanf committed Oct 22, 2012
1 parent 1fb00c8 commit 0f68717
Showing 1 changed file with 9 additions and 4 deletions.
Expand Up @@ -23,6 +23,7 @@
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -326,7 +327,8 @@ private static boolean ensureContentsSize(HTextFlowTarget target, int legalSize,
int contentsSize = target.getContents().size();
if (contentsSize < legalSize)
{
warnings.add("TextFlowTarget " + resId + " should have " + legalSize + " contents; filling with empty strings");
String warning = "Should have " + legalSize + " contents; adding empty strings: TextFlowTarget "+resId+" with contents: " + target.getContents();
warnings.add(warning);
List<String> newContents = new ArrayList<String>(legalSize);
newContents.addAll(target.getContents());
while (newContents.size() < legalSize)
Expand All @@ -338,7 +340,8 @@ private static boolean ensureContentsSize(HTextFlowTarget target, int legalSize,
}
else if (contentsSize > legalSize)
{
warnings.add("TextFlowTarget " + resId + " should have " + legalSize + " contents; discarding extra strings");
String warning = "Should have " + legalSize + " contents; discarding extra strings: TextFlowTarget "+resId+" with contents: " + target.getContents();
warnings.add(warning);
List<String> newContents = new ArrayList<String>(legalSize);
for (int i = 0; i < contentsSize; i++)
{
Expand Down Expand Up @@ -470,20 +473,23 @@ protected Boolean work() throws Exception
if (textFlow == null)
{
// return warning for unknown resId to caller
String warning = "Could not find text flow for message: " + incomingTarget.getContents();
String warning = "Could not find TextFlow for TextFlowTarget "+resId+" with contents: " + incomingTarget.getContents();
warnings.add(warning);
handle.addMessages(warning);
log.warn("skipping TextFlowTarget with unknown resId: {}", resId);
}
else
{
int nPlurals = getNumPlurals(hLocale, textFlow);
HTextFlowTarget hTarget = textFlowTargetDAO.getTextFlowTarget(textFlow, hLocale);
boolean targetChanged = false;
if (hTarget == null)
{
targetChanged = true;
log.debug("locale: {}", locale);
hTarget = new HTextFlowTarget(textFlow, hLocale);
List<String> contents = Collections.nCopies(nPlurals, "");
hTarget.setContents(contents);
hTarget.setVersionNum(0); // incremented when content is set
//textFlowTargetDAO.makePersistent(hTarget);
textFlow.getTargets().put(hLocale.getId(), hTarget);
Expand Down Expand Up @@ -533,7 +539,6 @@ else if (incomingTarget.getState() == ContentState.Approved)
throw new ZanataServiceException("unhandled merge type " + mergeType);
}
}
int nPlurals = getNumPlurals(hLocale, textFlow);
targetChanged |= adjustContentsAndState(hTarget, nPlurals, warnings);

// update translation information if applicable
Expand Down

0 comments on commit 0f68717

Please sign in to comment.