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

Commit

Permalink
Implement merge translation from existing version: https://bugzilla.r…
Browse files Browse the repository at this point in the history
…edhat.com/show_bug.cgi?id=1133989

Squashed commit of the following:

commit 59b3e04
Merge: 7f09ae2 4ea3f29
Author: Alex Eng <aeng@redhat.com>
Date:   Tue Mar 17 15:47:28 2015 +1000

    Merge branch 'integration/master' into rhbz1133989

    Conflicts:
    	zanata-war/src/main/resources/db/changelogs/db.changelog-3.7.xml

commit 7f09ae2
Author: Alex Eng <aeng@redhat.com>
Date:   Tue Mar 17 13:51:51 2015 +1000

    Limit to maintainer's projects to merge from in UI.

commit 2e96c94
Author: Alex Eng <aeng@redhat.com>
Date:   Mon Mar 16 16:09:57 2015 +1000

    Disable merge button if there's no version available to copy

commit 8be5f36
Author: Alex Eng <aeng@redhat.com>
Date:   Mon Mar 16 13:07:07 2015 +1000

    Update docs printscreen and messages

commit f8680c0
Author: Alex Eng <aeng@redhat.com>
Date:   Mon Mar 16 11:23:42 2015 +1000

    Add docs for merge-trans feature

commit 1b6e2b2
Author: Alex Eng <aeng@redhat.com>
Date:   Mon Mar 16 06:43:19 2015 +1000

    Fix unit test

commit 4e7d7be
Author: Alex Eng <aeng@redhat.com>
Date:   Sun Mar 15 14:43:26 2015 +1000

    Fix load source versions for merge trans dialog

commit 9e7c75d
Merge: f7eaffb 541fc6c
Author: Alex Eng <aeng@redhat.com>
Date:   Sun Mar 15 14:23:55 2015 +1000

    Merge branch 'integration/master' into rhbz1133989

commit f7eaffb
Author: Alex Eng <aeng@redhat.com>
Date:   Sun Mar 15 14:21:10 2015 +1000

    Refactor and changes on PR review

commit 6d4c388
Author: Alex Eng <aeng@redhat.com>
Date:   Fri Mar 13 16:38:32 2015 +1000

    Fix unit test

commit 0320132
Merge: f0419d1 baef61a
Author: Alex Eng <aeng@redhat.com>
Date:   Fri Mar 13 15:59:58 2015 +1000

    Merge branch 'integration/master' into rhbz1133989

commit f0419d1
Author: Alex Eng <aeng@redhat.com>
Date:   Fri Mar 13 15:29:04 2015 +1000

    Fix checkstyle

commit 16d58ba
Author: Alex Eng <aeng@redhat.com>
Date:   Fri Mar 13 15:10:15 2015 +1000

    Fixed project selector issue for merge trans

commit 5d1ce6f
Author: Alex Eng <aeng@redhat.com>
Date:   Thu Mar 12 15:57:35 2015 +1000

    WIP: implement project selector for merge translation dialog

commit fa50a89
Author: Alex Eng <aeng@redhat.com>
Date:   Thu Mar 12 14:09:04 2015 +1000

    Refactor query, UI and test

commit 43e9f07
Author: Alex Eng <aeng@redhat.com>
Date:   Wed Mar 11 18:32:42 2015 +1000

    Fix preload of progressBar component

commit 43bf35d
Author: Alex Eng <aeng@redhat.com>
Date:   Wed Mar 11 16:02:20 2015 +1000

    Rename js name unique

commit d42b558
Author: Alex Eng <aeng@redhat.com>
Date:   Tue Mar 10 15:57:38 2015 +1000

    Create loading component for copy actions

commit 511ed10
Author: Alex Eng <aeng@redhat.com>
Date:   Tue Mar 10 15:26:42 2015 +1000

    Create modal for merge-trans operations from version page

commit c05f4e6
Author: Alex Eng <aeng@redhat.com>
Date:   Mon Mar 9 15:13:12 2015 +1000

    Add unit test, fix shouldMerge to check for same content

commit b806517
Author: Alex Eng <aeng@redhat.com>
Date:   Fri Mar 6 16:34:55 2015 +1000

    WIP: add unit test for merge translation

commit f870517
Author: Alex Eng <aeng@redhat.com>
Date:   Fri Mar 6 11:10:21 2015 +1000

    Add unit test for merge translations

commit fd06390
Author: Alex Eng <aeng@redhat.com>
Date:   Thu Mar 5 15:38:07 2015 +1000

    Work in progress: add time log

commit 16b295d
Author: Alex Eng <aeng@redhat.com>
Date:   Thu Mar 5 15:04:49 2015 +1000

    Implement merge translation from and to existing version: https://bugzilla.redhat.com/show_bug.cgi?id=1133989
  • Loading branch information
Alex Eng committed Mar 17, 2015
1 parent 4ea3f29 commit bacdfcd
Show file tree
Hide file tree
Showing 37 changed files with 2,307 additions and 264 deletions.
Binary file added docs/images/version-merge-trans-cancel.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/version-merge-trans-dialog.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/version-merge-trans-progress.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/version-more-action-menu.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions docs/release-notes.md
Expand Up @@ -21,6 +21,10 @@ property can safely be reverted or removed before subsequent startups.

-----------------------

<h5>New Features</h5>

* [1133989](https://bugzilla.redhat.com/show_bug.cgi?id=1133989) - Copy translations from existing version.

## 3.6

<h5>New Editor (Alpha)</h5>
Expand Down
59 changes: 59 additions & 0 deletions docs/user-guide/merge-translations.md
@@ -0,0 +1,59 @@
# Merge translations from another project version

Merge translations allows project maintainers to copy translations across different project version based on matching context. (See below for context matching rules)

## Restrictions

- This feature is only available to project maintainers.
- Only translations that are in translated/approved state will be used.
- Merge translation can only be run if there are no other copy operations in progress for the selected version, such as copy-trans or copy version.

## Rule of which translations will be copied over
<table class='docutils'>
<tr>
<td>**From**</td><td>**To**</td><td>**Copy?**</td>
</tr>
<tr>
<td>fuzzy/untranslated</td><td>any</td><td>No</td>
</tr>
<tr>
<td>different source text/document id/<br />resId/msgctxt/locale</td><td>any</td><td>No</td>
</tr>
<tr>
<td>translated/approved</td><td>untranslated/fuzzy</td><td>Yes</td>
</tr>
<tr>
<td>translated/approved</td><td>translated/approved</td><td>copy if `From` is newer and <br />`Keep existing translated/approved translations` is unchecked</td>
</tr>
</table>
## Run Merge translations

1. Login to Zanata.
1. Select a project version you wish to copy translations to.
1. Expand `More Action` menu on top right corner and click on `Merge Translations`. This action is only available if you are a maintainer of the project.
<figure>
<img alt="More action menu in project version page" src="images/version-more-action-menu.png" />
</figure>
1. In displayed dialog, select the project-version you wish to copy translations from.
<figure>
<img alt="Merge translation dialog" src="images/version-merge-trans-dialog.png" />
</figure>
1. If you do not want to overwrite translated/approved translations, ensure that `Keep existing translated/approved translations` is checked. If this option is not checked, translated/approved translations will be replaced with newer translated/approved translations if they are available.
1. Click `Merge Translations` button to start the process.
1. The progress of the merge process is shown by a progress bar on the version page.
<figure>
<img alt="Merge translation in progress" src="images/version-merge-trans-progress.png" />
</figure>

## Cancel Merge translation
**_Note: This will only stop additional translations being merged. Any translations that have already been merged will remain merged._**

1. Go to the progress bar section in project version page.
1. Click on the `Cancel` button on top right panel.
<figure>
<img alt="Cancel merge translation in progress" src="images/version-merge-trans-cancel.png" />
</figure>



1 change: 1 addition & 0 deletions mkdocs.yml
Expand Up @@ -27,6 +27,7 @@ pages:
- ['user-guide/keyboard-shortcuts.md', 'User Guide', 'Keyboard Shortcuts']
- ['user-guide/project-types.md', 'User Guide', 'Project Types']
- ['user-guide/client-configuration.md', 'User Guide', 'Client Configuration']
- ['user-guide/merge-translations.md', 'User Guide', 'Merge translations']
## Project
- ['user-guide/projects/create-project.md', 'User Guide', 'Creating a Project']
- ['user-guide/projects/project-settings.md', 'User Guide', 'Project settings']
Expand Down
19 changes: 19 additions & 0 deletions zanata-model/src/main/java/org/zanata/model/HTextFlowTarget.java
Expand Up @@ -46,6 +46,7 @@
import javax.validation.constraints.NotNull;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

Expand Down Expand Up @@ -117,10 +118,25 @@ public class HTextFlowTarget extends ModelEntityBase implements HasContents,

private List<HTextFlowTargetReviewComment> reviewComments;

@Getter
private String revisionComment;

private boolean revisionCommentSet = false;

// Only for internal use (persistence transient)
@Setter(AccessLevel.PRIVATE)
private Integer oldVersionNum;

public void setRevisionComment(String revisionComment) {
this.revisionComment = revisionComment;
revisionCommentSet = true;
}

@Transient
boolean isRevisionCommentSet() {
return revisionCommentSet;
}

// Only for internal use (persistence transient)
@Setter(AccessLevel.PRIVATE)
private HTextFlowTargetHistory initialState;
Expand Down Expand Up @@ -411,6 +427,9 @@ private void preUpdate(HTextFlowTarget tft) {
// insert history if this has changed from its initial state
if (tft.initialState != null && tft.initialState.hasChanged(tft)) {
tft.getHistory().put(tft.oldVersionNum, tft.initialState);
if (!tft.isRevisionCommentSet()) {
tft.setRevisionComment(null);
}
}
}

Expand Down
Expand Up @@ -46,6 +46,8 @@
import org.zanata.common.ContentState;

import com.google.common.base.Objects;
import lombok.Getter;
import lombok.Setter;

@Entity
@Immutable
Expand Down Expand Up @@ -105,6 +107,10 @@ public static String getQueryNameMatchingHistory(int size) {

private HPerson reviewer;

@Getter
@Setter
private String revisionComment;

public HTextFlowTargetHistory() {
}

Expand All @@ -115,9 +121,11 @@ public HTextFlowTargetHistory(HTextFlowTarget target) {
this.textFlowRevision = target.getTextFlowRevision();
this.textFlowTarget = target;
this.versionNum = target.getVersionNum();
translator = target.getTranslator();
reviewer = target.getReviewer();
this.translator = target.getTranslator();
this.reviewer = target.getReviewer();
this.setContents(target.getContents());
this.revisionComment = target.getRevisionComment();

}

@Id
Expand Down Expand Up @@ -246,12 +254,13 @@ public boolean hasChanged(HTextFlowTarget current) {
this.lastModifiedBy)
|| !Objects.equal(current.getTranslator(), this.translator)
|| !Objects.equal(current.getReviewer(), this.reviewer)
|| !Objects.equal(current.getState(), this.state)
|| !Objects.equal(current.getState(), this.state)
|| !Objects.equal(current.getTextFlowRevision(),
this.textFlowRevision)
|| !Objects.equal(current.getLastChanged(), this.lastChanged)
|| !Objects.equal(current.getTextFlow().getId(),
this.textFlowTarget.getId())
|| !Objects.equal(current.getVersionNum(), this.versionNum);
|| !Objects.equal(current.getVersionNum(), this.versionNum)
|| !Objects.equal(current.getRevisionComment(), this.revisionComment);
}
}
49 changes: 28 additions & 21 deletions zanata-war/src/main/java/org/zanata/action/CopyTransAction.java
Expand Up @@ -30,14 +30,16 @@
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;
import org.zanata.async.handle.CopyTransTaskHandle;
import org.zanata.dao.ProjectIterationDAO;
import org.zanata.i18n.Messages;
import org.zanata.model.HCopyTransOptions;
import org.zanata.model.HProjectIteration;
import org.zanata.seam.scope.ConversationScopeMessages;
import org.zanata.service.impl.CopyTransOptionFactory;
import org.zanata.ui.ProgressBar;
import org.zanata.ui.CopyAction;
import org.zanata.util.DateUtil;
import com.google.common.base.Optional;

Expand All @@ -52,7 +54,7 @@
*/
@Name("copyTransAction")
@Scope(ScopeType.CONVERSATION)
public class CopyTransAction implements Serializable, ProgressBar {
public class CopyTransAction extends CopyAction implements Serializable {
private static final long serialVersionUID = 1L;

@In
Expand Down Expand Up @@ -86,35 +88,40 @@ public void onCreate() {
.getExplicitOptions());
}

@Override
public boolean isInProgress() {
return copyTransManager.isCopyTransRunning(getProjectIteration());
}

@Override
public String getProgressMessage() {
StringBuilder message = new StringBuilder();
message.append(
msgs.format("jsf.iteration.CopyTrans.processedItems",
getCurrentProgress(), getMaxProgress()))
.append(", ")
.append(msgs.format(
"jsf.iteration.CopyTrans.estimatedTimeRemaining",
getCopyTransEstimatedTimeLeft()));

return message.toString();
}

@Override
public void onComplete() {
FacesMessages.instance().add(StatusMessage.Severity.INFO,
msgs.format("jsf.iteration.CopyTrans.Completed",
getProjectSlug(), getIterationSlug()));
}

@Begin(join = true)
public void updateCopyTrans(String action, String value) {
copyTransOptionsModel.update(action, value);
}

@Override
public String getCompletedPercentage() {
CopyTransTaskHandle handle =
copyTransManager
.getCopyTransProcessHandle(getProjectIteration());
if (handle != null) {
double completedPercent =
(double) handle.getCurrentProgress() / (double) handle
.getMaxProgress() * 100;
if (Double.compare(completedPercent, 100) == 0) {
conversationScopeMessages
.setMessage(
FacesMessage.SEVERITY_INFO,
msgs.get("jsf.iteration.CopyTrans.Completed"));
}
return PERCENT_FORMAT.format(completedPercent);
} else {
return "0";
}
protected CopyTransTaskHandle getHandle() {
return copyTransManager
.getCopyTransProcessHandle(getProjectIteration());
}

public HProjectIteration getProjectIteration() {
Expand Down
Expand Up @@ -18,8 +18,9 @@
import org.zanata.service.CopyVersionService;

/**
* Manages copy version tasks.
*
* @author Alex Eng <a href="mailto:aeng@redhat.com">aeng@redhat.com</a>
* @author Carlos Munoz <a href="mailto:camunoz@redhat.com">aeng@redhat.com</a>
*/
@AutoCreate
@Name("copyVersionManager")
Expand All @@ -35,6 +36,16 @@ public class CopyVersionManager implements Serializable {
@In
private Identity identity;

/**
* Copy existing version to new version
*
* @param projectSlug
* - existing project identifier
* @param versionSlug
* - existing version identifier
* @param newVersionSlug
* - new version identifier
*/
public void startCopyVersion(String projectSlug, String versionSlug,
String newVersionSlug) {
CopyVersionKey key = CopyVersionKey.getKey(projectSlug, newVersionSlug);
Expand All @@ -44,6 +55,14 @@ public void startCopyVersion(String projectSlug, String versionSlug,
newVersionSlug, handle);
}

/**
* Cancel running copy version task
*
* @param projectSlug
* - target project identifier
* @param versionSlug
* - target version identifier
*/
public void cancelCopyVersion(String projectSlug, String versionSlug) {
if (isCopyVersionRunning(projectSlug, versionSlug)) {
CopyVersionTaskHandle handle =
Expand All @@ -68,11 +87,21 @@ public boolean isCopyVersionRunning(String projectSlug, String versionSlug) {
return handle != null && !handle.isDone();
}

/**
* Key used for copy version task
*
* @param projectSlug
* - target project identifier
* @param versionSlug
* - target version identifier
*/
@EqualsAndHashCode
@Getter
@AllArgsConstructor
public static final class CopyVersionKey implements Serializable {
// target project identifier
private final String projectSlug;
// target version identifier
private final String versionSlug;

public static CopyVersionKey getKey(String projectSlug,
Expand Down

0 comments on commit bacdfcd

Please sign in to comment.