Skip to content

Commit

Permalink
Handled locked status in SDLXLIFF
Browse files Browse the repository at this point in the history
  • Loading branch information
rmraya committed Nov 24, 2024
1 parent 60d6604 commit e08d3ea
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 10 deletions.
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 @@ -21,8 +21,8 @@ private Constants() {

public static final String TOOLID = "OpenXLIFF";
public static final String TOOLNAME = "OpenXLIFF Filters";
public static final String VERSION = "3.24.0";
public static final String BUILD = "20241122_0822";
public static final String VERSION = "3.25.0";
public static final String BUILD = "20241124_0807";

public static final String SUCCESS = "0";
public static final String ERROR = "1";
Expand Down
4 changes: 1 addition & 3 deletions src/com/maxprograms/converters/ditamap/DitaParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -652,9 +652,7 @@ private void addToImages(String imagePath, String href, String parentFile) {
JSONObject json = new JSONObject();
json.put("imagePath", imagePath);
json.put("href", href);
if (!images.containsKey(parentFile)) {
images.put(parentFile, new ArrayList<>());
}
images.computeIfAbsent(parentFile, s -> new ArrayList<String>());
List<String> list = images.get(parentFile);
String string = json.toString();
if (!list.contains(string)) {
Expand Down
41 changes: 39 additions & 2 deletions src/com/maxprograms/converters/sdlxliff/Sdl2Xliff.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,34 @@ && containsSrcText(root.getChild("source")))) {
}
Element segSource = root.getChild("seg-source");
Element target = root.getChild("target");

Map<String, Boolean> lockedMap = new HashMap<>();
Map<String, String> statusMap = new HashMap<>();

Element segDefs = root.getChild("sdl:seg-defs");
if (segDefs != null) {
List<Element> children = segDefs.getChildren("sdl:seg");
Iterator<Element> it = children.iterator();
while (it.hasNext()) {
Element sdlSeg = it.next();
String id = sdlSeg.getAttributeValue("id");
if ("true".equals(sdlSeg.getAttributeValue("locked", "false"))) {
lockedMap.put(id, true);
}
if ("Draft".equals(sdlSeg.getAttributeValue("conf"))) {
statusMap.put(id, "new");
}
if ("Translated".equals(sdlSeg.getAttributeValue("conf"))) {
statusMap.put(id, "translated");
}
if ("RejectedTranslation".equals(sdlSeg.getAttributeValue("conf"))) {
statusMap.put(id, "needs-review-translation");
}
if ("ApprovedSignOff".equals(sdlSeg.getAttributeValue("conf"))) {
statusMap.put(id, "signed-off");
}
}
}
if (segSource != null) {
if (containsText(segSource)) {
Map<String, Element> targets = new HashMap<>();
Expand All @@ -145,16 +173,25 @@ && containsSrcText(root.getChild("source")))) {
Iterator<Element> it = mrks.iterator();
while (it.hasNext()) {
Element mrk = it.next();
String id = mrk.getAttributeValue("mid");
String lockedString = "";
if (lockedMap.containsKey(id)) {
lockedString = "\" ts=\"locked";
}
writeStr(" <trans-unit id=\"" + root.getAttributeValue("id") + ':'
+ mrk.getAttributeValue("mid") + "\" xml:space=\"preserve\">\n");
+ mrk.getAttributeValue("mid") + lockedString + "\" xml:space=\"preserve\">\n");
// write new source
writeStr(" <source>");
recurseSource(mrk);
writeStr("</source>\n");
if (targets.containsKey(mrk.getAttributeValue("mid"))) {
// write new target
String stateString = "";
if (statusMap.containsKey(id)) {
stateString = " state=\"" + statusMap.get(id) + "\"";
}
Element tmrk = targets.get(mrk.getAttributeValue("mid"));
writeStr(" <target>");
writeStr(" <target " + stateString + ">");
recurseTarget(tmrk);
writeStr("</target>\n");
}
Expand Down
2 changes: 1 addition & 1 deletion src/com/maxprograms/converters/xml/Xliff2Xml.java
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ private static String extractText(Element element) throws SAXException {
} else {
String text = ((TextNode) n).getText();
if (isIdml && text.indexOf('\n') != -1) {
text = text.replaceAll("\\n", "");
text = text.replace("\n", "");
}
result = result + addEntities(text);
}
Expand Down
6 changes: 4 additions & 2 deletions src/com/maxprograms/xliff2/ToXliff2.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ private static void recurse(Element source, Element target) throws SAXException,
Attribute a = at.next();
if (a.getName().indexOf(':') != -1 && !a.getName().startsWith("xml:")) {
unit.setAttribute(a);
} else if (preserveAttributes.contains(a.getName())) {
} else if (preserveAttributes.contains(a.getName()) && !("ts".equals(a.getName()) && "locked".equals(a.getValue()))) {
otherAttributes.add(a);
}
}
Expand Down Expand Up @@ -429,7 +429,9 @@ private static void recurse(Element source, Element target) throws SAXException,
if (hasTarget) {
segment.addContent(tgt2);
}

if ("locked".equals(source.getAttributeValue("ts"))) {
segment.setAttribute("subState", "openxliff:locked");
}
List<Element> matches = source.getChildren("alt-trans");
if (!matches.isEmpty()) {
root2.setAttribute("xmlns:mtc", "urn:oasis:names:tc:xliff:matches:2.0");
Expand Down

0 comments on commit e08d3ea

Please sign in to comment.