Skip to content

Commit

Permalink
Improved support for Trados Studio Packages
Browse files Browse the repository at this point in the history
  • Loading branch information
rmraya committed Jun 18, 2022
1 parent 9aec0d8 commit dc0d3b5
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 13 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ With OpenXLIFF Filters you can create XLIFF files that don't use proprietary mar

Version | Comment | Release Date
--------|---------|-------------
2.4.2 | Improved support for Trados Studio Packages | june 18th, 2022
2.4.1 | Fixed conversion of third party XLIFF files | June 10th, 2022
2.4.0 | Added remove all targets; Added feedback for [Fluenta](https://www.maxprograms.com/products/fluenta.html) on DITA filter | June 9th, 2022
2.3.0 | Added copy source to target; Fixed DITA conversion and merge | May 25th, 2022
Expand Down
Binary file modified lib/openxliff.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions src/com/maxprograms/converters/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ private Constants() {

public static final String TOOLID = "OpenXLIFF";
public static final String TOOLNAME = "OpenXLIFF Filters";
public static final String VERSION = "2.4.1";
public static final String BUILD = "202200610_0740";
public static final String VERSION = "2.4.2";
public static final String BUILD = "202200618_1414";

public static final String SUCCESS = "0";
public static final String ERROR = "1";
Expand Down
3 changes: 0 additions & 3 deletions src/com/maxprograms/converters/Join.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,8 @@ public static void join(List<String> xliffs, String out)
writeString(output, ">\n");

Iterator<String> it = xliffs.iterator();
int count = 0;
while (it.hasNext()) {
String xliff = it.next();
count++;
Document doc = builder.build(xliff);
Element root = doc.getRootElement();
List<Element> files1 = root.getChildren("file");
Expand All @@ -180,7 +178,6 @@ public static void join(List<String> xliffs, String out)
Element file = files1.get(i);
String original = file.getAttributeValue("original");
file.setAttribute("original", Utils.makeRelativePath(treeRoot, original));
file.setAttribute("id", count + "-" + (i + 1));
Indenter.indent(file, 2, 2);
writeString(output, " ");
file.writeBytes(output, StandardCharsets.UTF_8);
Expand Down
6 changes: 3 additions & 3 deletions src/com/maxprograms/converters/sdlxliff/Sdl2Xliff.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,17 @@ && containsSrcText(root.getChild("source")))) {
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
38 changes: 36 additions & 2 deletions src/com/maxprograms/xliff2/FromXliff2.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.xml.sax.SAXException;

import com.maxprograms.converters.Constants;
import com.maxprograms.xml.Attribute;
import com.maxprograms.xml.Catalog;
import com.maxprograms.xml.Document;
import com.maxprograms.xml.Element;
Expand Down Expand Up @@ -118,6 +119,14 @@ private static void recurse(Element source, Element target) {
if (!trgLang.isEmpty()) {
file.setAttribute("target-language", trgLang);
}
List<Attribute> atts = source.getAttributes();
Iterator<Attribute> at = atts.iterator();
while (at.hasNext()) {
Attribute a = at.next();
if (a.getName().startsWith("xmlns:")) {
file.setAttribute(a);
}
}
Element header = new Element("header");
file.addContent(header);
Element body = new Element("body");
Expand Down Expand Up @@ -228,6 +237,17 @@ private static void recurse(Element source, Element target) {
if (source.getName().equals("unit")) {
Element transUnit = new Element("trans-unit");
transUnit.setAttribute("id", source.getAttributeValue("id"));
if ("no".equals(source.getAttributeValue("translate"))) {
transUnit.setAttribute("translate", "no");
}
List<Attribute> atts = source.getAttributes();
Iterator<Attribute> at = atts.iterator();
while (at.hasNext()) {
Attribute a = at.next();
if (a.getName().indexOf(':') != -1 && !a.getName().startsWith("xml:")) {
transUnit.setAttribute(a);
}
}
target.addContent(transUnit);

Map<String, String> tags = new HashMap<>();
Expand Down Expand Up @@ -265,6 +285,7 @@ private static void recurse(Element source, Element target) {
Element joinedTarget = new Element("target");
boolean approved = false;
boolean preserve = false;
boolean hasTarget = false;

List<Element> children = source.getChildren();
Iterator<Element> et = children.iterator();
Expand All @@ -278,6 +299,7 @@ private static void recurse(Element source, Element target) {
joinedSource.addContent(src.getContent());
Element tgt = child.getChild("target");
if (tgt != null) {
hasTarget = true;
joinedTarget.addContent(tgt.getContent());
}
if (tgt == null && child.getName().equals("ignorable")) {
Expand Down Expand Up @@ -311,7 +333,7 @@ private static void recurse(Element source, Element target) {
if (!joinedTarget.getContent().isEmpty()) {
tgt.setContent(harvestContent(joinedTarget, tags, attributes));
}
if (!tgt.getContent().isEmpty() || approved) {
if (hasTarget) {
if (preserve) {
transUnit.addContent("\n ");
}
Expand Down Expand Up @@ -481,6 +503,18 @@ private static Element processIniline(Element tag, Map<String, String> tags,
}
result = ph;
}
if (id.startsWith("x")) {
Element x = new Element("x");
x.setAttribute("id", id.substring("x".length()));
if (attributes != null && attributes.containsKey(id)) {
List<String[]> list = attributes.get(id);
for (int i = 0; i < list.size(); i++) {
String[] pair = list.get(i);
x.setAttribute(pair[0], pair[1]);
}
}
result = x;
}
if (id.startsWith("bpt")) {
Element bpt = new Element("bpt");
bpt.setAttribute("id", id.substring("bpt".length()));
Expand Down Expand Up @@ -559,7 +593,7 @@ private static Element processIniline(Element tag, Map<String, String> tags,
if ("pc".equals(tag.getName())) {
String id = tag.getAttributeValue("id");
Element g = new Element("g");
g.setAttribute("id", id);
g.setAttribute("id", id.substring("g".length()));
List<XMLNode> newContent = new ArrayList<>();
List<XMLNode> content = tag.getContent();
for (int i = 0; i < content.size(); i++) {
Expand Down
37 changes: 34 additions & 3 deletions src/com/maxprograms/xliff2/ToXliff2.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ private static void recurse(Element source, Element target) throws SAXException,
Element file = new Element("file");
file.setAttribute("id", "" + fileId++);
file.setAttribute("original", source.getAttributeValue("original"));
List<Attribute> atts = source.getAttributes();
Iterator<Attribute> at = atts.iterator();
while (at.hasNext()) {
Attribute a = at.next();
if (a.getName().startsWith("xmlns:")) {
file.setAttribute(a);
}
}

Element fileMetadata = new Element("mda:metadata");
Element typeGroup = new Element("mda:metaGroup");
Expand Down Expand Up @@ -169,7 +177,6 @@ private static void recurse(Element source, Element target) throws SAXException,
for (int i = 0; i < propGroups.size(); i++) {
Element sgroup = propGroups.get(i);
Element tgroup = new Element("mda:metaGroup");
tgroup.setAttribute("id", "" + i);
tgroup.setAttribute("category", sgroup.getAttributeValue("name"));
List<Element> props = sgroup.getChildren("prop");
Iterator<Element> it = props.iterator();
Expand Down Expand Up @@ -295,6 +302,14 @@ private static void recurse(Element source, Element target) throws SAXException,
if (source.getAttributeValue("translate", "yes").equals("no")) {
unit.setAttribute("translate", "no");
}
List<Attribute> atts = source.getAttributes();
Iterator<Attribute> at = atts.iterator();
while (at.hasNext()) {
Attribute a = at.next();
if (a.getName().indexOf(':') != -1 && !a.getName().startsWith("xml:")) {
unit.setAttribute(a);
}
}
target.addContent(unit);

List<Element> sourceNotes = new ArrayList<>();
Expand Down Expand Up @@ -354,12 +369,14 @@ private static void recurse(Element source, Element target) throws SAXException,
segment.addContent(src2);

Element tgt = source.getChild("target");
boolean hasTarget = true;
if (tgt == null) {
tgt = new Element("target");
hasTarget = false;
}
harvestInline(originalData, tagAttributes, tgt);
Element tgt2 = new Element("target");
if (source.getAttributeValue("xml:space", "default").equals("preserve")) {
if ("preserve".equals(source.getAttributeValue("xml:space"))) {
tgt2.setAttribute("xml:space", "preserve");
}
mrkCount = 1;
Expand All @@ -378,13 +395,15 @@ private static void recurse(Element source, Element target) throws SAXException,
}
}
if (!tgt2.getContent().isEmpty()) {
segment.addContent(tgt2);
if (!"final".equals(segment.getAttributeValue("state", "initial"))) {
segment.setAttribute("state", "translated");
}
} else {
segment.setAttribute("state", "initial");
}
if (hasTarget) {
segment.addContent(tgt2);
}

List<Element> matches = source.getChildren("alt-trans");
if (!matches.isEmpty()) {
Expand Down Expand Up @@ -479,6 +498,11 @@ private static void harvestInline(Element originalData, Element tagAttributes, E
}
return;
}
if ("x".equals(tag.getName())) {
String id = "x" + tag.getAttributeValue("id");
storeAttributes(tagAttributes, tag, id);
return;
}
List<Element> children = tag.getChildren();
Iterator<Element> it = children.iterator();
while (it.hasNext()) {
Expand Down Expand Up @@ -630,6 +654,13 @@ private static List<XMLNode> harvestContent(Element e, Element tagAttributes) th
result.add(pc);
return result;
}
if ("x".equals(e.getName())) {
Element ph = new Element("ph");
String id = "x" + e.getAttributeValue("id");
ph.setAttribute("id", id);
result.add(ph);
return result;
}
List<XMLNode> content = e.getContent();
Iterator<XMLNode> it = content.iterator();
while (it.hasNext()) {
Expand Down

0 comments on commit dc0d3b5

Please sign in to comment.