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

Commit

Permalink
Implement options for TM merge when encounter different meta info
Browse files Browse the repository at this point in the history
- when match percentage is not 100%
- when res id is different
- when doc id is different
- when project name is different
All the above will NOT make an auto-translation mark as approved.
First condition will make status fuzzy.
User can choose Approved, fuzzy or skip for last three conditions.
  • Loading branch information
Patrick Huang committed Jun 18, 2012
1 parent 8359711 commit 2ec7e17
Show file tree
Hide file tree
Showing 21 changed files with 758 additions and 101 deletions.
Expand Up @@ -18,6 +18,7 @@
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
* site: http://www.fsf.org.
*/

package org.zanata.service;

import org.zanata.common.LocaleId;
Expand Down
Expand Up @@ -21,15 +21,25 @@

package org.zanata.webtrans.client.presenter;

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

import org.zanata.common.ContentState;
import org.zanata.webtrans.client.editor.table.TableEditorPresenter;
import org.zanata.webtrans.client.events.NotificationEvent;
import org.zanata.webtrans.client.resources.UiMessages;
import org.zanata.webtrans.client.rpc.CachingDispatchAsync;
import org.zanata.webtrans.client.ui.TransMemoryMergePopupPanelDisplay;
import org.zanata.webtrans.shared.model.DocumentId;
import org.zanata.webtrans.shared.model.TransUnit;
import org.zanata.webtrans.shared.model.TransUnitId;
import org.zanata.webtrans.shared.rpc.MergeOption;
import org.zanata.webtrans.shared.rpc.NoOpResult;
import org.zanata.webtrans.shared.rpc.TransMemoryMerge;
import com.google.common.base.Preconditions;
import com.google.gwt.gen2.logging.shared.Log;
import com.allen_sauer.gwt.log.client.Log;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.inject.Inject;

Expand All @@ -48,15 +58,17 @@ public class TransMemoryMergePresenter extends WidgetPresenter<TransMemoryMergeP
private final EventBus eventBus;
private final CachingDispatchAsync dispatcher;
private final TableEditorPresenter tableEditorPresenter;
private final UiMessages messages;

@Inject
public TransMemoryMergePresenter(TransMemoryMergePopupPanelDisplay display, EventBus eventBus, CachingDispatchAsync dispatcher, TableEditorPresenter tableEditorPresenter)
public TransMemoryMergePresenter(TransMemoryMergePopupPanelDisplay display, EventBus eventBus, CachingDispatchAsync dispatcher, TableEditorPresenter tableEditorPresenter, UiMessages messages)
{
super(display, eventBus);
this.display = display;
this.eventBus = eventBus;
this.dispatcher = dispatcher;
this.tableEditorPresenter = tableEditorPresenter;
this.messages = messages;
display.setListener(this);
}

Expand All @@ -76,34 +88,66 @@ protected void onRevealDisplay()
}

@Override
public void proceedToMergeTM(String approvedPercent)
public void proceedToMergeTM(String percentage, MergeOption differentProjectOption, MergeOption differentDocumentOption, MergeOption differentResIdOption)
{
display.showProcessing();
DocumentId docId = tableEditorPresenter.getDocumentId();
Preconditions.checkNotNull(docId, "document id is null");
Collection<TransUnit> newItems = getUntranslatedItems();

Integer threshold = Integer.valueOf(approvedPercent);
dispatcher.execute(new TransMemoryMerge(threshold, docId), new AsyncCallback<NoOpResult>()
if (newItems.isEmpty())
{
eventBus.fireEvent(new NotificationEvent(Info, messages.noTranslationToMerge()));
display.hide();
return;
}

display.showProcessing();
TransMemoryMerge action = prepareTMMergeAction(newItems, percentage, differentProjectOption, differentDocumentOption, differentResIdOption);
dispatcher.execute(action, new AsyncCallback<NoOpResult>()
{
@Override
public void onFailure(Throwable caught)
{
Log.warning("failed:" + caught.getMessage());
//TODO localise string
eventBus.fireEvent(new NotificationEvent(Error, "Translation Memory merge failed"));
Log.warn("TM merge failed", caught);
eventBus.fireEvent(new NotificationEvent(Error, messages.mergeTMFailed()));
display.hide();
}

@Override
public void onSuccess(NoOpResult result)
{
eventBus.fireEvent(new NotificationEvent(Info, "Translation Memory merge success. Document reloaded."));
eventBus.fireEvent(new NotificationEvent(Info, messages.mergeTMSuccess()));
display.hide();
tableEditorPresenter.initialiseTransUnitList();
}
});
}

private Collection<TransUnit> getUntranslatedItems()
{
List<TransUnit> currentItems = tableEditorPresenter.getDisplay().getRowValues();
return Collections2.filter(currentItems, new Predicate<TransUnit>()
{
@Override
public boolean apply(TransUnit input)
{
return input.getStatus() == ContentState.New;
}
});
}

private TransMemoryMerge prepareTMMergeAction(Collection<TransUnit> newItems, String percentage, MergeOption differentProjectOption, MergeOption differentDocumentOption, MergeOption differentResIdOption)
{
Integer threshold = Integer.valueOf(percentage);
List<TransUnitId> unitIds = Lists.newArrayList(Collections2.transform(newItems, new Function<TransUnit, TransUnitId>()
{
@Override
public TransUnitId apply(TransUnit from)
{
return from.getId();
}
}));
return new TransMemoryMerge(threshold, unitIds, differentProjectOption, differentDocumentOption, differentResIdOption);
}

@Override
public void cancelMergeTM()
{
Expand Down
Expand Up @@ -35,4 +35,13 @@ public interface EnumMessages extends com.google.gwt.i18n.client.Messages

@DefaultMessage("Lucene")
String searchTypeRaw();

@DefaultMessage("Merge as need review")
String mergeAsFuzzy();

@DefaultMessage("Merge as approved")
String mergeAsApproved();

@DefaultMessage("Skip merge")
String skipMerge();
}
Expand Up @@ -84,4 +84,31 @@ public interface UiMessages extends Messages

@DefaultMessage("Select TM match percentage to pre-fill translations.")
String mergeTMCaption();

@DefaultMessage("No text has new status to be merged.")
String noTranslationToMerge();

@DefaultMessage("Translation Memory merge failed")
String mergeTMFailed();

@DefaultMessage("Translation Memory merge success. Document reloaded.")
String mergeTMSuccess();

@DefaultMessage("Proceed to auto-fill")
String mergeTMConfirm();

@DefaultMessage("Cancel")
String mergeTMCancel();

@DefaultMessage("Match percentage threshold")
String matchThreshold();

@DefaultMessage("Different project")
String differentProjectSlug();

@DefaultMessage("Different document")
String differentDocument();

@DefaultMessage("Different resource ID")
String differentResId();
}
Expand Up @@ -19,18 +19,15 @@ public class EnumRenderer<T extends Enum<?>> extends AbstractRenderer<T>
@Override
public String render(T object)
{
if (object == null)
return emptyValue;
if (object == null)
{
return emptyValue;
}
return object.toString();
}

public String getEmptyValue()
{
return emptyValue;
}

public void setEmptyValue(String emptyValue)
{
this.emptyValue = emptyValue;
}
}
@@ -0,0 +1,59 @@
/*
* Copyright 2012, Red Hat, Inc. and individual contributors as indicated by the
* @author tags. See the copyright.txt file in the distribution for a full
* listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this software; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
* site: http://www.fsf.org.
*/

package org.zanata.webtrans.client.ui;

import org.zanata.webtrans.client.resources.EnumMessages;
import org.zanata.webtrans.shared.rpc.HasSearchType.SearchType;
import org.zanata.webtrans.shared.rpc.MergeOption;
import com.google.inject.Inject;
import com.google.inject.Singleton;

/**
* @author Patrick Huang <a href="mailto:pahuang@redhat.com">pahuang@redhat.com</a>
*/
@Singleton
public class MergeOptionRenderer extends EnumRenderer<MergeOption>
{
private final EnumMessages messages;

@Inject
public MergeOptionRenderer(EnumMessages messages)
{
this.messages = messages;
}

@Override
public String render(MergeOption option)
{
switch (option)
{
case FUZZY:
return messages.mergeAsFuzzy();
case APPROVED:
return messages.mergeAsApproved();
case SKIP:
return messages.skipMerge();
default:
return getEmptyValue();
}
}
}
Expand Up @@ -21,6 +21,7 @@

package org.zanata.webtrans.client.ui;

import org.zanata.webtrans.shared.rpc.MergeOption;
import com.google.common.base.Preconditions;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
Expand All @@ -31,6 +32,7 @@
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.inject.Inject;

/**
* @author Patrick Huang <a href="mailto:pahuang@redhat.com">pahuang@redhat.com</a>
Expand All @@ -42,22 +44,27 @@ public class TMMergeForm extends Composite
private TransMemoryMergePopupPanelDisplay.Listener listener;

@UiField
ListBox approvedPercent;
ListBox matchThreshold;
@UiField
Button confirmButton;
@UiField
Button cancelButton;
@UiField(provided = true)
EnumListBox<MergeOption> differentProject;
@UiField(provided = true)
EnumListBox<MergeOption> differentDocument;
@UiField(provided = true)
EnumListBox<MergeOption> differentResId;

public TMMergeForm()
@Inject
public TMMergeForm(MergeOptionRenderer mergeOptionRenderer)
{
differentProject = new EnumListBox<MergeOption>(MergeOption.class, mergeOptionRenderer);
differentDocument = new EnumListBox<MergeOption>(MergeOption.class, mergeOptionRenderer);
differentResId = new EnumListBox<MergeOption>(MergeOption.class, mergeOptionRenderer);
initWidget(uiBinder.createAndBindUi(this));
}

public String getSelectedApprovedPercent()
{
return approvedPercent.getValue(approvedPercent.getSelectedIndex());
}

public void setListener(TransMemoryMergePopupPanelDisplay.Listener listener)
{
this.listener = listener;
Expand All @@ -67,7 +74,12 @@ public void setListener(TransMemoryMergePopupPanelDisplay.Listener listener)
public void onConfirmButtonClick(ClickEvent event)
{
Preconditions.checkNotNull(listener, "Do you forget to call setListener on TMMergeForm?");
listener.proceedToMergeTM(getSelectedApprovedPercent());
listener.proceedToMergeTM(getSelectedMatchThreshold(), differentProject.getValue(), differentDocument.getValue(), differentResId.getValue());
}

private String getSelectedMatchThreshold()
{
return matchThreshold.getValue(matchThreshold.getSelectedIndex());
}

@UiHandler("cancelButton")
Expand Down

0 comments on commit 2ec7e17

Please sign in to comment.