Skip to content

Commit

Permalink
Fixed import of XLIFF matches
Browse files Browse the repository at this point in the history
  • Loading branch information
rmraya committed Oct 18, 2020
1 parent d87be6d commit dc9e5bc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 28 deletions.
Binary file modified lib/openxliff.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion src/com/maxprograms/converters/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private Constants() {
public static final String TOOLID = "OpenXLIFF";
public static final String TOOLNAME = "OpenXLIFF Filters";
public static final String VERSION = "1.11.1";
public static final String BUILD = "20201014_1434";
public static final String BUILD = "20201018_1009";

public static final String SUCCESS = "0";
public static final String ERROR = "1";
Expand Down
20 changes: 5 additions & 15 deletions src/com/maxprograms/converters/xliff/ToOpenXliff.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,20 +170,15 @@ private static void recurse2x(Element root, List<Element> units) {
while (it.hasNext()) {
Element match = it.next();
String ref = match.getAttributeValue("ref");
if (ref.equals(segment.getAttributeValue("id"))) {
if (ref.equals("#" + segment.getAttributeValue("id"))) {
Element altTrans = new Element("alt-trans");
String origin = match.getAttributeValue("origin");
if (!origin.isEmpty()) {
altTrans.setAttribute("origin", origin);
}
String quality = altTrans.getAttributeValue("matchQuality");
String quality = match.getAttributeValue("matchQuality");
if (!quality.isBlank()) {
try {
double percentage = Double.parseDouble(quality);
altTrans.setAttribute("match-quality", "" + percentage);
} catch (NumberFormatException e) {
// ignore
}
altTrans.setAttribute("match-quality", quality);
}
Element altSource = new Element("source");
altSource.setContent(getContent2x(match.getChild("source")));
Expand Down Expand Up @@ -379,14 +374,9 @@ private static void recurse1x(Element root, List<Element> units) {
if (!origin.isEmpty()) {
altTrans.setAttribute("origin", origin);
}
String quality = altTrans.getAttributeValue("match-quality");
String quality = match.getAttributeValue("match-quality");
if (!quality.isBlank()) {
try {
double percentage = Double.parseDouble(quality);
altTrans.setAttribute("match-quality", "" + percentage);
} catch (NumberFormatException e) {
// ignore
}
altTrans.setAttribute("match-quality", quality);
}
Element altSource = new Element("source");
altSource.setContent(getContent1x(match.getChild("source")));
Expand Down
25 changes: 13 additions & 12 deletions src/com/maxprograms/xliff2/ToXliff2.java
Original file line number Diff line number Diff line change
Expand Up @@ -448,23 +448,24 @@ private static void recurse(Element source, Element target) {
Element mtc = new Element("mtc:matches");
unit.getContent().add(0, mtc);
for (int i = 0; i < matches.size(); i++) {
Element smatch = matches.get(i);
Element tmatch = new Element("mtc:match");
tmatch.setAttribute("ref", "#" + source.getAttributeValue("id"));
String matchQuality = smatch.getAttributeValue("match-quality");
Element altTrans = matches.get(i);
Element match = new Element("mtc:match");
match.setAttribute("ref", "#" + source.getAttributeValue("id"));
String matchQuality = altTrans.getAttributeValue("match-quality");
if (!matchQuality.isEmpty()) {
try {
tmatch.setAttribute("matchQuality", "" + Float.parseFloat(matchQuality));
Float quality = Float.parseFloat(matchQuality);
match.setAttribute("matchQuality", "" + quality);
} catch (NumberFormatException nf) {
// ignore
}
}
String origin = smatch.getAttributeValue("origin");
String origin = altTrans.getAttributeValue("origin");
if (!origin.isEmpty()) {
tmatch.setAttribute("origin", origin);
match.setAttribute("origin", origin);
}
Element tsrc = new Element("source");
List<XMLNode> content = smatch.getChild("source").getContent();
List<XMLNode> content = altTrans.getChild("source").getContent();
Iterator<XMLNode> snodes = content.iterator();
while (snodes.hasNext()) {
XMLNode node = snodes.next();
Expand Down Expand Up @@ -498,9 +499,9 @@ private static void recurse(Element source, Element target) {
}
}
}
tmatch.addContent(tsrc);
match.addContent(tsrc);
Element ttgt = new Element("target");
content = smatch.getChild("target").getContent();
content = altTrans.getChild("target").getContent();
snodes = content.iterator();
while (snodes.hasNext()) {
XMLNode node = snodes.next();
Expand Down Expand Up @@ -534,8 +535,8 @@ private static void recurse(Element source, Element target) {
}
}
}
tmatch.addContent(ttgt);
mtc.addContent(tmatch);
match.addContent(ttgt);
mtc.addContent(match);
}
}
if (originalData.getChildren("data").isEmpty()) {
Expand Down

0 comments on commit dc9e5bc

Please sign in to comment.