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

Commit

Permalink
Fix Qt source content for download translated
Browse files Browse the repository at this point in the history
Cannot use tags in ts content.
Also clean up a few unnecessary lines and output.
  • Loading branch information
djansen-redhat committed Apr 21, 2016
1 parent da6e114 commit f1723cc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ protected TextFlow processTextFlow(TextUnit tu, String content, String subDocNam
return tf;
}

private String getTranslatableText(TextUnit tu) {
protected String getTranslatableText(TextUnit tu) {
String letterCodedText =
GenericContent.fromFragmentToLetterCoded(tu.getSource()
.getFirstContent(), true);
Expand Down
22 changes: 17 additions & 5 deletions zanata-war/src/main/java/org/zanata/adapter/TSAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import net.sf.okapi.common.filterwriter.IFilterWriter;
import net.sf.okapi.common.resource.RawDocument;
import net.sf.okapi.common.resource.StartSubDocument;
import net.sf.okapi.common.resource.TextContainer;
import net.sf.okapi.common.resource.TextUnit;
import net.sf.okapi.filters.ts.TsFilter;
import org.apache.commons.io.FilenameUtils;
Expand Down Expand Up @@ -89,7 +90,6 @@ protected void generateTranslatedFile(URI originalFile,
if (rawDoc.getTargetLocale() == null) {
rawDoc.setTargetLocale(localeId);
}

List<String> encounteredIds = new ArrayList<>();
IFilter filter = getFilter();
try {
Expand All @@ -106,21 +106,28 @@ protected void generateTranslatedFile(URI originalFile,
} else if (event.getEventType() == EventType.TEXT_UNIT) {
TextUnit tu = (TextUnit) event.getResource();
if (!tu.getSource().isEmpty() && tu.isTranslatable()) {
String translatable = GenericContent.fromFragmentToLetterCoded(
tu.getSource().getFirstContent(), true);
String translatable = getTranslatableText(tu);
// Ignore if the source is empty
if (!translatable.isEmpty()) {
TextFlowTarget tft = translations.get(getIdFor(tu, translatable, subDocName));
String targetTft = getIdFor(tu, translatable, subDocName);
TextFlowTarget tft = translations.get(targetTft);
if (tft != null) {
String id = getIdFor(tu, translatable, subDocName);
if(!encounteredIds.contains(id)) {
// Dismiss duplicate numerusforms
encounteredIds.add(id);
for (String translated : tft.getContents()) {
// TODO: Find a method of doing this in one object, not a loop
tu.setTargetContent(localeId, GenericContent
.fromLetterCodedToFragment(translated,
tu.getSource().getFirstContent(), true, true));
// Empty fragment here, else the source is altered
new TextContainer("").getUnSegmentedContentCopy(),
true, true));
writer.handleEvent(event);
}
}
} else {
writer.handleEvent(event);
}
}
}
Expand All @@ -138,6 +145,11 @@ protected void generateTranslatedFile(URI originalFile,
}
}

@Override
protected String getTranslatableText(TextUnit tu) {
return tu.getSource().getFirstContent().getText();
}

@Override
protected TextFlow processTextFlow(TextUnit tu, String content, String subDocName, LocaleId sourceLocale) {
TextFlow tf = new TextFlow(getIdFor(tu, content,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,6 @@ public ValidTargetFilterPredicate(LocaleId localeId) {
@Override
public boolean apply(Object[] input) {
Object entity = input[1];
log.info("Array size is {}", input.length);
if (entity instanceof HTextFlowTarget) {
HTextFlowTarget target = (HTextFlowTarget) entity;
if (!target.getLocaleId().equals(localeId)) {
Expand Down

0 comments on commit f1723cc

Please sign in to comment.