diff --git a/lib/openxliff.jar b/lib/openxliff.jar index 37998f05..2d501329 100644 Binary files a/lib/openxliff.jar and b/lib/openxliff.jar differ diff --git a/src/com/maxprograms/converters/Constants.java b/src/com/maxprograms/converters/Constants.java index abedf5cd..9b00b30c 100644 --- a/src/com/maxprograms/converters/Constants.java +++ b/src/com/maxprograms/converters/Constants.java @@ -20,7 +20,7 @@ private Constants() { public static final String TOOLID = "OpenXLIFF"; public static final String TOOLNAME = "OpenXLIFF Filters"; public static final String VERSION = "3.5.0"; - public static final String BUILD = "20230329_0558"; + public static final String BUILD = "2023031_0958"; public static final String SUCCESS = "0"; public static final String ERROR = "1"; diff --git a/src/com/maxprograms/xliff2/Resegmenter.java b/src/com/maxprograms/xliff2/Resegmenter.java index 0b9bbf1a..3adbedd4 100644 --- a/src/com/maxprograms/xliff2/Resegmenter.java +++ b/src/com/maxprograms/xliff2/Resegmenter.java @@ -39,6 +39,8 @@ public class Resegmenter { private static Segmenter segmenter; + private static boolean canResegment; + private static boolean translate; private Resegmenter() { // do not instantiate this class @@ -50,6 +52,7 @@ public static List run(String xliff, String srx, String srcLang, Catalog try { segmenter = new Segmenter(srx, srcLang, catalog); SAXBuilder builder = new SAXBuilder(); + builder.setEntityResolver(catalog); Document doc = builder.build(xliff); Element root = doc.getRootElement(); recurse(root); @@ -84,16 +87,25 @@ private static boolean surroundedWithTags(Element e) { } private static void recurse(Element root) throws SAXException, IOException, ParserConfigurationException { + if ("file".equals(root.getName())) { + canResegment = "yes".equals(root.getAttributeValue("canResegment", "yes")); + translate = "yes".equals(root.getAttributeValue("translate", "yes")); + } else if (root.hasAttribute("canResegment")) { + canResegment = "yes".equals(root.getAttributeValue("canResegment", canResegment ? "yes" : "no")); + translate = "yes".equals(root.getAttributeValue("translate", translate ? "yes" : "no")); + } if ("unit".equals(root.getName())) { - if (root.getChildren("segment").size() == 1) { + if (translate && canResegment && root.getChildren("segment").size() == 1) { Element segment = root.getChild("segment"); + String originalId = segment.getAttributeValue("id"); + String unitId = root.getAttributeValue("id"); Element source = segment.getChild("source"); Element target = segment.getChild("target"); boolean isSourceCopy = target != null && source.getContent().equals(target.getContent()); boolean isEmpty = target != null && target.getContent().isEmpty(); if (target == null || isSourceCopy || isEmpty) { - root.removeAttribute("canResegment"); Element segSource = segmenter.segment(source); + int newSegments = segSource.getChildren("mrk").size(); int id = 0; root.removeChild(segment); List content = segSource.getContent(); @@ -109,7 +121,6 @@ private static void recurse(Element root) throws SAXException, IOException, Pars Element firstTag = e.getChildren().get(0); if (!hasText(firstTag)) { Element ignorable = new Element("ignorable"); - ignorable.setAttribute("id", root.getAttributeValue("id") + '-' + id++); Element ignorableSource = new Element("source"); ignorableSource.setAttribute("xml:space", "preserve"); ignorable.addContent(ignorableSource); @@ -136,7 +147,7 @@ private static void recurse(Element root) throws SAXException, IOException, Pars if (!hasText(e)) { newSeg = new Element("ignorable"); } - newSeg.setAttribute("id", root.getAttributeValue("id") + '-' + id++); + newSeg.setAttribute("id", newSegments == 1 ? originalId : unitId + '-' + id++); root.addContent(newSeg); Element newSource = new Element("source"); newSource.setAttribute("xml:space", source.getAttributeValue("xml:space", "default")); @@ -153,7 +164,6 @@ private static void recurse(Element root) throws SAXException, IOException, Pars newTarget.addContent(e.getContent()); } if (lastIgnorable != null) { - lastIgnorable.setAttribute("id", root.getAttributeValue("id") + '-' + id++); root.addContent(lastIgnorable); } } else {