Skip to content

Commit

Permalink
Accepted tracked changes in SDLXLIFF
Browse files Browse the repository at this point in the history
  • Loading branch information
rmraya committed Aug 31, 2023
1 parent 9a4a9a2 commit 63f8a19
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 9 deletions.
Binary file modified lib/openxliff.jar
Binary file not shown.
17 changes: 16 additions & 1 deletion src/com/maxprograms/converters/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
*******************************************************************************/
package com.maxprograms.converters;

import org.json.JSONObject;

public class Constants {

private Constants() {
Expand All @@ -20,9 +22,22 @@ private Constants() {
public static final String TOOLID = "OpenXLIFF";
public static final String TOOLNAME = "OpenXLIFF Filters";
public static final String VERSION = "3.14.0";
public static final String BUILD = "20230829_1929";
public static final String BUILD = "20230831_1219";

public static final String SUCCESS = "0";
public static final String ERROR = "1";
public static final String CANCELLED = "Cancelled";

public static void main(String[] args) {
JSONObject json = new JSONObject();
json.put("toolId", TOOLID);
json.put("toolName", TOOLNAME);
json.put("version", VERSION);
json.put("build", BUILD);
json.put("java", System.getProperty("java.version"));
json.put("javaVendor", System.getProperty("java.vendor"));
json.put("xmlVersion", com.maxprograms.xml.Constants.VERSION);
json.put("xmlBuild", com.maxprograms.xml.Constants.BUILD);
System.out.println(json.toString(2));
}
}
52 changes: 44 additions & 8 deletions src/com/maxprograms/converters/sdlxliff/Sdl2Xliff.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,15 @@ public static List<String> run(Map<String, String> params) {
writeStr("<?encoding " + doc.getEncoding() + "?>\n");

writeStr("<header>\n");
writeStr("<skl>\n");
writeStr("<external-file href=\"" + Utils.cleanString(skeletonFile) + "\"/>\n");
writeStr("</skl>\n");
writeStr(" <tool tool-version=\"" + Constants.VERSION + " " + Constants.BUILD + "\" tool-id=\""
writeStr(" <skl>\n");
writeStr(" <external-file href=\"" + Utils.cleanString(skeletonFile) + "\"/>\n");
writeStr(" </skl>\n");
writeStr(" <tool tool-version=\"" + Constants.VERSION + " " + Constants.BUILD + "\" tool-id=\""
+ Constants.TOOLID + "\" tool-name=\"" + Constants.TOOLNAME + "\"/>\n");
writeStr("</header>\n");
writeStr("<body>\n");

acceptTrackedChanges(doc.getRootElement());
recurse(doc.getRootElement());

writeStr("</body>\n");
Expand Down Expand Up @@ -144,20 +145,20 @@ && containsSrcText(root.getChild("source")))) {
Iterator<Element> it = mrks.iterator();
while (it.hasNext()) {
Element mrk = it.next();
writeStr("<trans-unit id=\"" + root.getAttributeValue("id") + ':'
writeStr(" <trans-unit id=\"" + root.getAttributeValue("id") + ':'
+ mrk.getAttributeValue("mid") + "\" xml:space=\"preserve\">\n");
// write new source
writeStr(" <source>");
writeStr(" <source>");
recurseSource(mrk);
writeStr("</source>\n");
if (targets.containsKey(mrk.getAttributeValue("mid"))) {
// write new target
Element tmrk = targets.get(mrk.getAttributeValue("mid"));
writeStr(" <target>");
writeStr(" <target>");
recurseTarget(tmrk);
writeStr("</target>\n");
}
writeStr(" </trans-unit>\n");
writeStr(" </trans-unit>\n");
}
}
}
Expand Down Expand Up @@ -276,4 +277,39 @@ private static boolean containsText(Element source) {
private static void writeStr(String string) throws IOException {
out.write(string.getBytes(StandardCharsets.UTF_8));
}

private static void acceptTrackedChanges(Element e) {
List<Element> children = e.getChildren("mrk");
if (!children.isEmpty()) {
List<XMLNode> content = e.getContent();
List<XMLNode> newContent = new ArrayList<>();
Iterator<XMLNode> it = content.iterator();
while (it.hasNext()) {
XMLNode n = it.next();
if (n.getNodeType() == XMLNode.ELEMENT_NODE) {
Element child = (Element) n;
if (child.getName().equals("mrk")) {
if (child.getAttributeValue("mtype").equals("x-sdl-added")) {
acceptTrackedChanges(child);
newContent.addAll(child.getContent());
} else if (child.getAttributeValue("mtype").equals("x-sdl-deleted")) {
// do nothing
} else {
newContent.add(child);
}
} else {
newContent.add(child);
}
} else {
newContent.add(n);
}
}
e.setContent(newContent);
}
children = e.getChildren();
Iterator<Element> it = children.iterator();
while (it.hasNext()) {
acceptTrackedChanges(it.next());
}
}
}

0 comments on commit 63f8a19

Please sign in to comment.