diff --git a/lib/openxliff.jar b/lib/openxliff.jar index c33c191e..8b255a1f 100644 Binary files a/lib/openxliff.jar and b/lib/openxliff.jar differ diff --git a/src/com/maxprograms/xliff2/ToXliff2.java b/src/com/maxprograms/xliff2/ToXliff2.java index a000c397..aae42a24 100644 --- a/src/com/maxprograms/xliff2/ToXliff2.java +++ b/src/com/maxprograms/xliff2/ToXliff2.java @@ -27,6 +27,7 @@ import javax.xml.parsers.ParserConfigurationException; 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; @@ -257,7 +258,6 @@ private static void recurse(Element source, Element target) { space.addContent("keep"); metaGroup.addContent(space); } - } target.addContent(group); target = group; @@ -287,20 +287,38 @@ private static void recurse(Element source, Element target) { unit.addContent(originalData); Element src = source.getChild("source"); - List tags = src.getChildren("ph"); + List tags = src.getChildren(); Set tagSet = new TreeSet<>(); for (int i = 0; i < tags.size(); i++) { - Element ph = tags.get(i); - String id = "ph" + ph.getAttributeValue("id"); - if (!tagSet.contains(id)) { - Element data = new Element("data"); - data.setAttribute("id", id); - data.setContent(ph.getContent()); - originalData.addContent(data); - tagSet.add("ph" + ph.getAttributeValue("id")); + Element tag = tags.get(i); + if ("ph".equals(tag.getName())) { + String id = "ph" + tag.getAttributeValue("id"); + if (!tagSet.contains(id)) { + Element data = new Element("data"); + data.setAttribute("id", id); + data.setContent(tag.getContent()); + originalData.addContent(data); + tagSet.add("ph" + tag.getAttributeValue("id")); + } + } + if ("g".equals(tag.getName())) { + String id = "g" + tag.getAttributeValue("id"); + if (!tagSet.contains(id)) { + Element head = new Element("data"); + head.setAttribute("id", id); + head.setText(getHead(tag)); + originalData.addContent(head); + tagSet.add("g" + tag.getAttributeValue("id")); + + Element tail = new Element("data"); + tail.setAttribute("id", "/g" + tag.getAttributeValue("id")); + tail.setText(""); + originalData.addContent(tail); + tagSet.add("/g" + tag.getAttributeValue("id")); + } } } - + Element segment = new Element("segment"); segment.setAttribute("id", source.getAttributeValue("id")); unit.addContent(segment); @@ -328,6 +346,17 @@ private static void recurse(Element source, Element target) { ph.setAttribute("dataRef", "ph" + tag.getAttributeValue("id")); src2.addContent(ph); } + if (tag.getName().equals("g")) { + Element head = new Element("ph"); + head.setAttribute("id", "g" + tag.getAttributeValue("id")); + head.setAttribute("dataRef", "g" + tag.getAttributeValue("id")); + src2.addContent(head); + src2.addContent(tag.getText()); + Element tail = new Element("ph"); + tail.setAttribute("id", "/g" + tag.getAttributeValue("id")); + tail.setAttribute("dataRef", "/g" + tag.getAttributeValue("id")); + src2.addContent(tail); + } if (tag.getName().equals("mrk")) { Element mrk = new Element("mrk"); mrk.setAttribute("id", "mrk" + tag.getAttributeValue("mid")); @@ -373,6 +402,31 @@ private static void recurse(Element source, Element target) { ph.setAttribute("dataRef", id); tgt2.addContent(ph); } + if (tag.getName().equals("g")) { + String id = "g" + tag.getAttributeValue("id"); + if (!tagSet.contains(id)) { + Element head = new Element("data"); + head.setAttribute("id", id); + head.setText(getHead(tag)); + originalData.addContent(head); + tagSet.add("g" + tag.getAttributeValue("id")); + + Element tail = new Element("data"); + tail.setAttribute("id", "/g" + tag.getAttributeValue("id")); + tail.setText(""); + originalData.addContent(tail); + tagSet.add("/g" + tag.getAttributeValue("id")); + } + Element head = new Element("ph"); + head.setAttribute("id", id); + head.setAttribute("dataRef", id); + tgt2.addContent(head); + tgt2.addContent(tag.getText()); + Element tail = new Element("ph"); + tail.setAttribute("id", "/g" + tag.getAttributeValue("id")); + tail.setAttribute("dataRef", "/g" + tag.getAttributeValue("id")); + tgt2.addContent(tail); + } if (tag.getName().equals("mrk")) { Element mrk = new Element("mrk"); mrk.setAttribute("id", "mrk" + tag.getAttributeValue("mid")); @@ -421,8 +475,8 @@ private static void recurse(Element source, Element target) { Element tag = (Element) node; if (tag.getName().equals("ph")) { Element ph = new Element("ph"); - String id = "ph" + tag.getAttributeValue("id"); - ph.setAttribute("id",id); + String id = "ph" + tag.getAttributeValue("id"); + ph.setAttribute("id", id); if (!tagSet.contains(id)) { Element data = new Element("data"); data.setAttribute("id", id); @@ -457,8 +511,8 @@ private static void recurse(Element source, Element target) { Element tag = (Element) node; if (tag.getName().equals("ph")) { Element ph = new Element("ph"); - String id = "ph" + tag.getAttributeValue("id"); - ph.setAttribute("id",id); + String id = "ph" + tag.getAttributeValue("id"); + ph.setAttribute("id", id); if (!tagSet.contains(id)) { Element data = new Element("data"); data.setAttribute("id", id); @@ -496,4 +550,18 @@ private static void recurse(Element source, Element target) { } } + private static String getHead(Element e) { + StringBuilder builder = new StringBuilder(); + builder.append('<'); + builder.append(e.getName()); + List atts = e.getAttributes(); + Iterator it = atts.iterator(); + while (it.hasNext()) { + Attribute a = it.next(); + builder.append(' '); + builder.append(a.toString()); + } + builder.append('>'); + return builder.toString(); + } }