diff --git a/jars/openxliff.jar b/jars/openxliff.jar index c3bd5a4..833cd03 100644 Binary files a/jars/openxliff.jar and b/jars/openxliff.jar differ diff --git a/package.json b/package.json index 8291337..455bd83 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "swordfish", "productName": "Swordfish", - "version": "4.2.0", + "version": "4.2.1", "description": "Swordfish Translation Editor", "main": "js/App.js", "scripts": { @@ -19,9 +19,8 @@ "type": "git", "url": "https://github.com/rmraya/Swordfish.git" }, - "dependencies": {}, "devDependencies": { - "electron": "^11.2.3", - "typescript": "^4.1.5" + "electron": "^12.0.1", + "typescript": "^4.2.3" } } diff --git a/src/com/maxprograms/swordfish/Constants.java b/src/com/maxprograms/swordfish/Constants.java index 426630e..14c29d6 100644 --- a/src/com/maxprograms/swordfish/Constants.java +++ b/src/com/maxprograms/swordfish/Constants.java @@ -25,8 +25,8 @@ private Constants() { } public static final String APPNAME = "Swordfish"; - public static final String VERSION = "4.2.0"; - public static final String BUILD = "20210217_1214"; + public static final String VERSION = "4.2.1"; + public static final String BUILD = "20210316_1104"; public static final String REASON = "reason"; public static final String STATUS = "status"; diff --git a/src/com/maxprograms/swordfish/ProjectsHandler.java b/src/com/maxprograms/swordfish/ProjectsHandler.java index e90ccce..6255a43 100644 --- a/src/com/maxprograms/swordfish/ProjectsHandler.java +++ b/src/com/maxprograms/swordfish/ProjectsHandler.java @@ -838,7 +838,7 @@ private JSONObject saveSource(String request) { String project = json.getString("project"); try { projectStores.get(project).saveSource(json); - } catch (IOException | SQLException | SAXException | ParserConfigurationException | DataFormatException e) { + } catch (IOException | SQLException | SAXException | ParserConfigurationException e) { logger.log(Level.ERROR, e); result.put(Constants.REASON, e.getMessage()); } diff --git a/src/com/maxprograms/swordfish/xliff/XliffStore.java b/src/com/maxprograms/swordfish/xliff/XliffStore.java index f1ba5c0..1bc8dae 100644 --- a/src/com/maxprograms/swordfish/xliff/XliffStore.java +++ b/src/com/maxprograms/swordfish/xliff/XliffStore.java @@ -30,6 +30,7 @@ Redistribution of this Software or parts of it in any form (source code or import java.lang.System.Logger.Level; import java.net.URISyntaxException; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; @@ -181,9 +182,9 @@ public XliffStore(String xliffFile, String sourceLang, String targetLang) conn.commit(); boolean needsUpgrade = false; - try (Statement stmt = conn.createStatement()) { + try (Statement stm = conn.createStatement()) { String sql = "SELECT TYPE_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='UNITS' AND COLUMN_NAME='DATA'"; - try (ResultSet rs = stmt.executeQuery(sql)) { + try (ResultSet rs = stm.executeQuery(sql)) { while (rs.next()) { needsUpgrade = !rs.getString(1).equalsIgnoreCase("CLOB"); } @@ -889,13 +890,13 @@ public synchronized JSONObject saveSegment(JSONObject json) getSource.setString(2, unit); getSource.setString(3, segment); boolean wasFinal = false; - boolean translate = true; + boolean translatable = true; try (ResultSet rs = getSource.executeQuery()) { while (rs.next()) { src = TMUtils.getString(rs.getNCharacterStream(1)); pureSource = TMUtils.getString(rs.getNCharacterStream(2)); wasFinal = rs.getString(3).equals("final"); - translate = rs.getString(4).equals("Y"); + translatable = rs.getString(4).equals("Y"); } } Element source = buildElement(src); @@ -929,7 +930,7 @@ public synchronized JSONObject saveSegment(JSONObject json) } result.put("propagated", propagated); - boolean checkErrors = translate && (confirm || (!pureTarget.isEmpty() && acceptUnconfirmed)); + boolean checkErrors = translatable && (confirm || (!pureTarget.isEmpty() && acceptUnconfirmed)); boolean tagErrors = false; boolean spaceErrors = false; @@ -969,7 +970,7 @@ public void run() { } public synchronized void saveSource(JSONObject json) - throws IOException, SQLException, SAXException, ParserConfigurationException, DataFormatException { + throws IOException, SQLException, SAXException, ParserConfigurationException { String file = json.getString("file"); String unit = json.getString("unit"); @@ -1791,10 +1792,64 @@ public void exportTranslations(String output) throws SAXException, IOException, ParserConfigurationException, SQLException { updateXliff(); getPreferences(); - List result = Merge.merge(xliffFile, output, catalog, acceptUnconfirmed); + File adjusted = reviewStates(); + List result = Merge.merge(adjusted.getAbsolutePath(), output, catalog, acceptUnconfirmed); if (!"0".equals(result.get(0))) { throw new IOException(result.get(1)); } + Files.delete(adjusted.toPath()); + } + + private File reviewStates() throws SAXException, IOException, ParserConfigurationException { + File xliff = new File(xliffFile); + File adjusted = new File(xliff.getParentFile(), "adjusted.xlf"); + document = builder.build(xliffFile); + recurseStates(document.getRootElement()); + XMLOutputter outputter = new XMLOutputter(); + outputter.preserveSpace(true); + Indenter.indent(document.getRootElement(), 2); + try (FileOutputStream out = new FileOutputStream(adjusted)) { + outputter.output(document, out); + } + return adjusted; + } + + private void recurseStates(Element e) { + if ("segment".equals(e.getName())) { + if ("initial".equals(e.getAttributeValue("state"))) { + Element source = e.getChild("source"); + Element target = e.getChild("target"); + if (target == null) { + target = new Element("target"); + target.setAttribute("xml:lang", tgtLang); + if ("preserve".equals(source.getAttributeValue("xml:space", "default"))) { + target.setAttribute("xml:space", "preserve"); + } + e.addContent(target); + } + target.setContent(source.getContent()); + } + return; + } + if ("ignorable".equals(e.getName())) { + Element target = e.getChild("target"); + if (target == null) { + Element source = e.getChild("source"); + target = new Element("target"); + target.setAttribute("xml:lang", tgtLang); + if ("preserve".equals(source.getAttributeValue("xml:space", "default"))) { + target.setAttribute("xml:space", "preserve"); + } + target.setContent(source.getContent()); + e.addContent(target); + } + return; + } + List children = e.getChildren(); + Iterator it = children.iterator(); + while (it.hasNext()) { + recurseStates(it.next()); + } } public void updateXliff() throws SQLException, SAXException, IOException, ParserConfigurationException {