Skip to content

Commit

Permalink
Updated for release 4.15.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rmraya committed Mar 3, 2022
1 parent 45f184a commit cc57f92
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 31 deletions.
Binary file modified jars/openxliff.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "swordfish",
"productName": "Swordfish",
"version": "4.14.0",
"version": "4.15.0",
"description": "Swordfish Translation Editor",
"main": "js/App.js",
"scripts": {
Expand All @@ -20,7 +20,7 @@
"url": "https://github.com/rmraya/Swordfish.git"
},
"devDependencies": {
"electron": "^17.0.0",
"electron": "^17.1.0",
"typescript": "^4.5.5"
}
}
4 changes: 2 additions & 2 deletions src/com/maxprograms/swordfish/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ private Constants() {
}

public static final String APPNAME = "Swordfish";
public static final String VERSION = "4.14.0";
public static final String BUILD = "20220206_0744";
public static final String VERSION = "4.15.0";
public static final String BUILD = "20220302_1504";

public static final String REASON = "reason";
public static final String STATUS = "status";
Expand Down
97 changes: 95 additions & 2 deletions src/com/maxprograms/swordfish/xliff/XliffStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.sql.Statement;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -1971,9 +1972,45 @@ private void recurseUpdating(Element e)
insertGlossary(e, glossary);
}
Element matches = getUnitMatches(currentFile, currentUnit);
Map<String, Element> matchesData = new HashMap<>();
if (matches != null) {
List<Element> matchesList = matches.getChildren("mtc:match");
Iterator<Element> it = matchesList.iterator();
while (it.hasNext()) {
Element match = it.next();
Element originalData = match.getChild("originalData");
if (originalData != null) {
List<Element> dataList = originalData.getChildren("data");
for (int i = 0; i < dataList.size(); i++) {
Element data = dataList.get(i);
matchesData.put(data.getAttributeValue("id"), data);
}
}
}
insertMatches(e, matches);
}
if (!matchesData.isEmpty()) {
Element originalData = e.getChild("originalData");
if (originalData == null) {
originalData = new Element("originalData");
insertOriginalData(e, originalData);
}
Map<String, Element> oldData = new HashMap<>();
List<Element> dataList = originalData.getChildren("data");
for (int i = 0; i < dataList.size(); i++) {
Element data = dataList.get(i);
oldData.put(data.getAttributeValue("id"), data);
}
Set<String> keys = matchesData.keySet();
Iterator<String> it = keys.iterator();
while (it.hasNext()) {
String key = it.next();
if (!oldData.containsKey(key)) {
oldData.put(key, matchesData.get(key));
originalData.addContent(matchesData.get(key));
}
}
}
Element notes = getUnitNotes(currentFile, currentUnit);
if (notes != null) {
insertNotes(e, notes);
Expand Down Expand Up @@ -2045,6 +2082,29 @@ private void recurseUpdating(Element e)
}
}

private void insertOriginalData(Element unit, Element originalData) {
List<XMLNode> newContent = new Vector<>();
boolean added = false;
List<XMLNode> oldContent = unit.getContent();
Iterator<XMLNode> it = oldContent.iterator();
while (it.hasNext()) {
XMLNode node = it.next();
if (node.getNodeType() == XMLNode.ELEMENT_NODE) {
Element e = (Element) node;
if ("segment".equals(e.getName()) || "ignorable".equals(e.getName())) {
if (!added) {
newContent.add(originalData);
added = true;
}
}
newContent.add(node);
} else {
newContent.add(node);
}
}
unit.setContent(newContent);
}

private void insertMatches(Element unit, Element matches) {
Element old = unit.getChild("mtc:matches");
if (old != null) {
Expand Down Expand Up @@ -2098,18 +2158,51 @@ private Element getUnitMatches(String file, String unit)
match.setAttribute("origin", rs.getString(5));
match.setAttribute("type", rs.getString(6));
match.setAttribute("matchQuality", "" + rs.getInt(7));
Element originalData = new Element("originalData");
String data = TMUtils.getString(rs.getNCharacterStream(10));
if (!data.isEmpty()) {
match.addContent(XliffUtils.buildElement(data));
originalData = XliffUtils.buildElement(data);
List<Element> newData = new Vector<>();
List<Element> oldData = originalData.getChildren();
Iterator<Element> it = oldData.iterator();
while (it.hasNext()) {
Element d = it.next();
if (!d.getContent().isEmpty()) {
newData.add(d);
}
}
originalData.setChildren(newData);
if (!newData.isEmpty()) {
match.addContent(originalData);
}
}
Set<String> dataRefs = new HashSet<>();
Iterator<Element> it = originalData.getChildren().iterator();
while (it.hasNext()) {
dataRefs.add(it.next().getAttributeValue("id"));
}
match.addContent(XliffUtils.buildElement(TMUtils.getString(rs.getNCharacterStream(8))));
match.addContent(XliffUtils.buildElement(TMUtils.getString(rs.getNCharacterStream(9))));
removeMissingReferences(match.getChild("source"), dataRefs);
removeMissingReferences(match.getChild("target"), dataRefs);
matches.addContent(match);
}
}
return matches.getChildren("mtc:match").isEmpty() ? null : matches;
}

private void removeMissingReferences(Element child, Set<String> references) {
List<Element> tags = child.getChildren();
Iterator<Element> it = tags.iterator();
while (it.hasNext()) {
Element tag = it.next();
String dataRef = tag.getAttributeValue("dataRef");
if (!dataRef.isEmpty() && !references.contains(dataRef)) {
tag.removeAttribute("dataRef");
}
}
}

private Element getUnitNotes(String file, String unit) throws SQLException, IOException {
Element notes = new Element("notes");
unitNotes.setString(1, file);
Expand Down Expand Up @@ -3062,7 +3155,7 @@ public String generateStatistics()

writeString(out, "<p><b>Int. Rep.</b>: Internal Repetition - Segment repetitions within one document<br>");
writeString(out, "<b>Ext. Rep.</b>: External Repetition - Segment repetitions between all documents</p>");

it = files.iterator();
count = 1;
int projectSegments = 0;
Expand Down
5 changes: 4 additions & 1 deletion src/com/maxprograms/swordfish/xliff/XliffUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -220,6 +221,7 @@ public static Element toXliff(String segId, int match, String name, Element tuv)
Element xliff = new Element(name);
List<XMLNode> newContent = new Vector<>();
List<XMLNode> content = tuv.getChild("seg").getContent();
Map<String,String> pairs = new HashMap<>();
Iterator<XMLNode> it = content.iterator();
int tag = 0;
while (it.hasNext()) {
Expand All @@ -244,12 +246,13 @@ public static Element toXliff(String segId, int match, String name, Element tuv)
sc.setAttribute("dataRef", segId + "_" + match + "_sc" + tag);
newContent.add(sc);
tags.put(segId + "_" + match + "_sc" + tag, e.getText());
pairs.put(e.getAttributeValue("i"), segId + "_" + match + "_sc" + tag);
}
if ("ept".equals(e.getName())) {
Element ec = new Element("ec");
tag++;
ec.setAttribute("id", segId + "_" + match + "_ec" + tag);
ec.setAttribute("dataRef", segId + "_" + match + "_ec" + tag);
ec.setAttribute("startRef", pairs.get(e.getAttributeValue("i")));
newContent.add(ec);
tags.put(segId + "_" + match + "_ec" + tag, e.getText());
}
Expand Down
36 changes: 14 additions & 22 deletions ts/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class Swordfish {
mkdirSync(Swordfish.appHome, { recursive: true });
}

this.ls = spawn(this.javapath, ['-cp', 'lib/h2-1.4.200.jar', '--module-path', 'lib', '-m', 'swordfish/com.maxprograms.swordfish.TmsServer', '-port', '8070'], { cwd: app.getAppPath() });
this.ls = spawn(this.javapath, ['-cp', 'lib/h2-1.4.200.jar', '--module-path', 'lib', '-m', 'swordfish/com.maxprograms.swordfish.TmsServer', '-port', '8070'], { cwd: app.getAppPath(), windowsHide: true });

this.ls.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
Expand All @@ -208,8 +208,7 @@ class Swordfish {
}
});

execFileSync(this.javapath, ['--module-path', 'lib', '-m', 'openxliff/com.maxprograms.server.CheckURL', 'http://localhost:8070/TMSServer'], { cwd: app.getAppPath() });

execFileSync(this.javapath, ['--module-path', 'lib', '-m', 'openxliff/com.maxprograms.server.CheckURL', 'http://localhost:8070/TMSServer'], { cwd: app.getAppPath(), windowsHide: true });
this.loadDefaults();
Swordfish.locations = new Locations(Swordfish.path.join(app.getPath('appData'), app.name, 'locations.json'));
Swordfish.loadPreferences();
Expand Down Expand Up @@ -244,12 +243,12 @@ class Swordfish {
type: 'warning',
message: 'You are running a version for Macs with Intel processors on a Mac with Apple M1 chipset.'
});
}
}
});
});

app.on('before-quit', (event: Event) => {
if (this.ls) {
if (!this.ls.killed) {
event.preventDefault();
this.stopServer();
}
Expand Down Expand Up @@ -1262,19 +1261,16 @@ class Swordfish {
stopServer(): void {
if (!this.stopping) {
this.stopping = true;
Swordfish.sendRequest('/', { command: 'stop' },
(data: any) => {
if (data.status === 'OK') {
this.ls = null;
app.quit();
} else {
console.log('error stopping server ', JSON.stringify(data));
}
},
(reason: string) => {
Swordfish.showMessage({ type: 'error', message: reason });
}
);
let request: ClientRequest = net.request({
url: 'http://127.0.0.1:8070/',
method: 'POST'
});
request.setHeader('Content-Type', 'application/json');
request.setHeader('Accept', 'application/json');
request.write(JSON.stringify({ command: 'stop' }));
request.end();
this.ls.kill();
app.quit();
}
}

Expand Down Expand Up @@ -3178,7 +3174,6 @@ class Swordfish {
(data: any) => {
if (data.status !== Swordfish.SUCCESS) {
Swordfish.showMessage({ type: 'error', message: data.reason });
return;
}
},
(reason: string) => {
Expand All @@ -3192,7 +3187,6 @@ class Swordfish {
(data: any) => {
if (data.status !== Swordfish.SUCCESS) {
Swordfish.showMessage({ type: 'error', message: data.reason });
return;
}
},
(reason: string) => {
Expand Down Expand Up @@ -4429,7 +4423,6 @@ class Swordfish {
(data: any) => {
if (data.status !== Swordfish.SUCCESS) {
Swordfish.showMessage({ type: 'error', message: data.reason });
return;
}
},
(reason: string) => {
Expand Down Expand Up @@ -4518,7 +4511,6 @@ class Swordfish {
(data: any) => {
if (data.status !== Swordfish.SUCCESS) {
Swordfish.showMessage({ type: 'error', message: data.reason });
return;
}
},
(reason: string) => {
Expand Down
2 changes: 0 additions & 2 deletions ts/translation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1362,12 +1362,10 @@ class TranslationView {

nextUntranslated(): void {
this.saveEdit({ confirm: false, next: 'untranslated' });
return;
}

nextUnconfirmed(): void {
this.saveEdit({ confirm: false, next: 'unconfirmed' });
return;
}

centerRow(row: HTMLTableRowElement): void {
Expand Down

0 comments on commit cc57f92

Please sign in to comment.