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

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix ContentState calculations to consider nPlurals and move into Cont…
…entStateUtil
  • Loading branch information
seanf committed May 16, 2012
1 parent 8c8cefc commit 1c584d0
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 149 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Expand Up @@ -19,9 +19,9 @@
</scm>

<properties>
<zanata.api.version>1.6.0-alpha-2</zanata.api.version>
<zanata.api.version>1.6.0-alpha-3-SNAPSHOT</zanata.api.version>
<zanata.client.version>1.6.0-alpha-2</zanata.client.version>
<zanata.common.version>1.6.0-alpha-2</zanata.common.version>
<zanata.common.version>1.6.0-alpha-3-SNAPSHOT</zanata.common.version>
</properties>

<dependencyManagement>
Expand Down
Expand Up @@ -20,12 +20,16 @@
*/
package org.zanata.action;

import java.io.InputStream;
import java.util.List;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.security.Restrict;
import org.jboss.seam.faces.FacesMessages;
import org.jboss.seam.international.StatusMessage.Severity;
import org.zanata.common.EntityStatus;
import org.zanata.common.LocaleId;
import org.zanata.common.MergeType;
Expand All @@ -41,19 +45,12 @@
import org.zanata.rest.StringSet;
import org.zanata.rest.dto.extensions.ExtensionType;
import org.zanata.rest.dto.resource.Resource;
import org.zanata.rest.dto.resource.TextFlowTarget;
import org.zanata.rest.dto.resource.TranslationsResource;
import org.zanata.security.ZanataIdentity;
import org.zanata.service.DocumentService;
import org.zanata.service.TranslationFileService;
import org.zanata.service.TranslationService;

import java.io.InputStream;
import java.util.Collection;
import java.util.List;

import static org.jboss.seam.international.StatusMessage.Severity;

@Name("projectIterationFilesAction")
@Scope(ScopeType.PAGE)
public class ProjectIterationFilesAction
Expand Down Expand Up @@ -138,21 +135,21 @@ public void uploadTranslationFile()
this.translationFileUpload.getFileName());

// translate it
Collection<TextFlowTarget> resourcesNotFound =
List<String> warnings =
this.translationServiceImpl.translateAllInDoc(this.projectSlug, this.iterationSlug, this.translationFileUpload.getDocId(),
new LocaleId(this.localeId), transRes, new StringSet(ExtensionType.GetText.toString()),
this.translationFileUpload.getMergeTranslations() ? MergeType.AUTO : MergeType.IMPORT);

StringBuilder facesInfoMssg = new StringBuilder("File {0} uploaded.");
if( resourcesNotFound.size() > 0 )
if (!warnings.isEmpty())
{
facesInfoMssg.append(" There were some warnings, see below.");
}

FacesMessages.instance().add(Severity.INFO, facesInfoMssg.toString(), this.translationFileUpload.getFileName());
for( TextFlowTarget nf : resourcesNotFound )
for (String warning : warnings)
{
FacesMessages.instance().add(Severity.WARN, "Could not find text flow for message: {0}", nf.getContents());
FacesMessages.instance().add(Severity.WARN, warning);
}
}
catch (ZanataServiceException zex)
Expand Down
Expand Up @@ -279,10 +279,6 @@ public boolean transferFromTextFlowTarget(TextFlowTarget from, HTextFlowTarget t
to.setState(from.getState());
changed = true;
}
if (changed)
{
to.setVersionNum(to.getVersionNum() + 1);
}
return changed;
}

Expand Down
Expand Up @@ -20,7 +20,33 @@
*/
package org.zanata.rest.service;

import com.google.common.base.Function;
import static org.zanata.rest.service.SourceDocResource.RESOURCE_SLUG_TEMPLATE;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.EntityTag;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.UriInfo;

import org.codehaus.enunciate.jaxrs.TypeHint;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
Expand All @@ -44,41 +70,11 @@
import org.zanata.model.HTextFlowTarget;
import org.zanata.rest.NoSuchEntityException;
import org.zanata.rest.ReadOnlyEntityException;
import org.zanata.rest.dto.resource.TextFlowTarget;
import org.zanata.rest.dto.resource.TranslationsResource;
import org.zanata.security.ZanataIdentity;
import org.zanata.service.CopyTransService;
import org.zanata.service.LocaleService;
import org.zanata.service.TranslationService;
import org.zanata.util.StringUtil;

import javax.annotation.Nullable;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.EntityTag;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.UriInfo;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import static org.zanata.rest.service.SourceDocResource.RESOURCE_SLUG_TEMPLATE;

@Name("translatedDocResourceService")
@Path(TranslatedDocResourceService.SERVICE_PATH)
Expand Down Expand Up @@ -355,34 +351,21 @@ public Response putTranslations(@PathParam("id") String idNoSlash, @PathParam("l
}

// Translate
Collection<TextFlowTarget> unknownResIds =
List<String> warnings =
this.translationServiceImpl.translateAllInDoc(projectSlug, iterationSlug, id, locale, messageBody, extensions, mergeType);


// Regenerate etag in case it has changed
// TODO create valid etag
etag = eTagUtils.generateETagForDocument(hProjectIteration, id, new HashSet<String>(0));

log.debug("successful put translation");
// TODO lastChanged
if (unknownResIds.isEmpty())
{
return Response.ok().tag(etag).build();
}
else
StringBuilder sb = new StringBuilder();
for (String warning : warnings)
{
String resIdStr = StringUtil.concat(unknownResIds, ',',
new Function<TextFlowTarget, String>()
{
@Override
public String apply(@Nullable TextFlowTarget from)
{
return from.getResId();
}
}
);
return Response.ok("warning: unknown resIds: " + unknownResIds).tag(etag).build();
sb.append("warning: ").append(warning).append('\n');
}
return Response.ok(sb.toString()).tag(etag).build();
}

private HProjectIteration retrieveAndCheckIteration(boolean writeOperation)
Expand Down
Expand Up @@ -20,7 +20,6 @@
*/
package org.zanata.service;

import java.util.Collection;
import java.util.List;
import java.util.Set;

Expand All @@ -29,7 +28,6 @@
import org.zanata.common.MergeType;
import org.zanata.exception.ConcurrentTranslationException;
import org.zanata.model.HTextFlowTarget;
import org.zanata.rest.dto.resource.TextFlowTarget;
import org.zanata.rest.dto.resource.TranslationsResource;
import org.zanata.webtrans.shared.model.TransUnitUpdateRequest;

Expand Down Expand Up @@ -66,9 +64,10 @@ public interface TranslationService
* @param extensions The extensions to use while translating
* @param mergeType Indicates how to handle the translations. AUTO will merge the new translations with the provided
* ones. IMPORT will overwrite all existing translations with the new ones.
* @return A list of text flow targets that could not be matched to any text flows in the source document.
* @return A list of warnings about text flow targets that (a) could not be matched to any text flows in the source document
* or (b) whose states don't match their contents.
*/
Collection<TextFlowTarget> translateAllInDoc(String projectSlug, String iterationSlug, String docId, LocaleId locale, TranslationsResource translations, Set<String> extensions,
List<String> translateAllInDoc(String projectSlug, String iterationSlug, String docId, LocaleId locale, TranslationsResource translations, Set<String> extensions,
MergeType mergeType);

public interface TranslationResult
Expand Down

0 comments on commit 1c584d0

Please sign in to comment.