Skip to content

Commit

Permalink
Updated for release 4.17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rmraya committed May 11, 2022
1 parent 66f5aa8 commit f69fc55
Show file tree
Hide file tree
Showing 27 changed files with 195 additions and 116 deletions.
Binary file modified jars/openxliff.jar
Binary file not shown.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "swordfish",
"productName": "Swordfish",
"version": "4.16.0",
"version": "4.17.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": "^18.1.0",
"typescript": "^4.6.3"
"electron": "^18.2.2",
"typescript": "^4.6.4"
}
}
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.16.0";
public static final String BUILD = "20220423_0737";
public static final String VERSION = "4.17.0";
public static final String BUILD = "20220511_1419";

public static final String REASON = "reason";
public static final String STATUS = "status";
Expand Down
5 changes: 2 additions & 3 deletions src/com/maxprograms/swordfish/ProjectsHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,7 @@ public void run() {
projectStores.get(project).exportXliff(output);
obj.put(Constants.PROGRESS, Constants.COMPLETED);
processes.put(id, obj);
} catch (IOException | SAXException | ParserConfigurationException | SQLException
| URISyntaxException e) {
} catch (IOException | SAXException | ParserConfigurationException | SQLException e) {
logger.log(Level.ERROR, e);
obj.put(Constants.PROGRESS, Constants.ERROR);
obj.put(Constants.REASON, e.getMessage());
Expand Down Expand Up @@ -1424,7 +1423,7 @@ private JSONObject exportHTML(String request) {
}
String export = projectStores.get(project).exportHTML(prj.getDescription());
result.put("export", export);
} catch (SQLException | IOException | SAXException | ParserConfigurationException | DataFormatException e) {
} catch (SQLException | IOException | SAXException | ParserConfigurationException e) {
logger.log(Level.ERROR, e);
result.put(Constants.REASON, e.getMessage());
}
Expand Down
3 changes: 1 addition & 2 deletions src/com/maxprograms/swordfish/ServicesHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -578,8 +578,7 @@ private static JSONObject getSubjects() throws IOException {
private static JSONObject getSystemInformation() {
JSONObject result = new JSONObject();
result.put("swordfish", Constants.VERSION + " Build: " + Constants.BUILD);
result.put("openxliff",
com.maxprograms.converters.Constants.VERSION + " Build: " + com.maxprograms.converters.Constants.BUILD);
result.put("openxliff", com.maxprograms.converters.Constants.VERSION + " Build: " + com.maxprograms.converters.Constants.BUILD);
result.put("java", System.getProperty("java.version") + " Vendor: " + System.getProperty("java.vendor"));
return result;
}
Expand Down
9 changes: 7 additions & 2 deletions src/com/maxprograms/swordfish/tm/InternalDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class InternalDatabase implements ITmEngine {
protected static final Logger logger = System.getLogger(InternalDatabase.class.getName());

private String dbname;
private String url;
private Connection conn;
private PreparedStatement storeTUV;
private PreparedStatement deleteTUV;
Expand All @@ -84,7 +85,7 @@ public InternalDatabase(String dbname, String workFolder) throws SQLException, I
if (!exists) {
database.mkdirs();
}
String url = "jdbc:h2:" + database.getAbsolutePath() + "/db";
url = "jdbc:h2:" + database.getAbsolutePath() + "/db";
conn = DriverManager.getConnection(url);

if (!exists) {
Expand Down Expand Up @@ -594,6 +595,11 @@ public void setCreationDate(String date) {
@Override
public Element getTu(String tuid) throws SQLException, SAXException, IOException, ParserConfigurationException {
Element tu = tuDb.getTu(tuid);
if (tu == null) {
tu = new Element("tu");
tu.setAttribute("tuid", tuid);
logger.log(Level.WARNING, "tu is null for tuid " + tuid); // TODO repair TU
}
try (PreparedStatement stmt = conn.prepareStatement("SELECT lang, seg FROM tuv WHERE tuid=?")) {
stmt.setString(1, tuid);
try (ResultSet rs = stmt.executeQuery()) {
Expand Down Expand Up @@ -722,5 +728,4 @@ public JSONArray batchTranslate(JSONObject params)
}
return result;
}

}
30 changes: 2 additions & 28 deletions src/com/maxprograms/swordfish/xliff/Skeletons.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,33 +37,6 @@ private Skeletons() {
// private for security
}

public static void embedSkeletons(String xliffFile, String outputFile)
throws SAXException, IOException, ParserConfigurationException, URISyntaxException {
SAXBuilder builder = new SAXBuilder();
builder.setEntityResolver(new Catalog(XliffStore.getCatalog()));
Document doc = builder.build(xliffFile);
Element xliff = doc.getRootElement();
List<Element> files = xliff.getChildren("file");
Iterator<Element> it = files.iterator();
while (it.hasNext()) {
Element file = it.next();
Element skeleton = file.getChild("skeleton");
if (skeleton != null) {
String href = skeleton.getAttributeValue("href");
if (!href.isEmpty()) {
File skl = new File(href);
skeleton.addContent(Utils.encodeFromFile(skl.getAbsolutePath()));
skeleton.removeAttribute("href");
}
}
}
try (FileOutputStream out = new FileOutputStream(outputFile)) {
XMLOutputter outputter = new XMLOutputter();
outputter.preserveSpace(true);
outputter.output(doc, out);
}
}

public static void extractSkeletons(File xliffFile, File outputFile) throws IOException, SAXException,
ParserConfigurationException, URISyntaxException {
File xliffParent = outputFile.getParentFile();
Expand All @@ -79,7 +52,8 @@ public static void extractSkeletons(File xliffFile, File outputFile) throws IOEx
if (skeleton != null) {
String href = skeleton.getAttributeValue("href");
if (href.isEmpty()) {
File skl = File.createTempFile("file", ".skl", xliffParent);

File skl = new File(xliffParent, file.getAttributeValue("original") + ".skl");
Utils.decodeToFile(skeleton.getText(), skl.getAbsolutePath());
skeleton.setAttribute("href", skl.getAbsolutePath());
skeleton.setContent(new Vector<>());
Expand Down
99 changes: 99 additions & 0 deletions src/com/maxprograms/swordfish/xliff/Split.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*******************************************************************************
* Copyright (c) 2007-2022 Maxprograms.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 1.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-v10.html
*
* Contributors:
* Maxprograms - initial API and implementation
*******************************************************************************/

package com.maxprograms.swordfish.xliff;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import javax.xml.parsers.ParserConfigurationException;

import com.maxprograms.converters.Utils;
import com.maxprograms.xml.Document;
import com.maxprograms.xml.Element;
import com.maxprograms.xml.SAXBuilder;
import com.maxprograms.xml.XMLOutputter;

import org.xml.sax.SAXException;

public class Split {

private Split() {
// empty for security
}

public static List<String> split(String xliff, String outputFolder)
throws SAXException, IOException, ParserConfigurationException {
List<String> result = new ArrayList<>();
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(xliff);
Element root = doc.getRootElement();
if (!"xliff".equals(root.getName())) {
throw new IOException("Selected file is not an XLIFF document");
}
File folder = new File(outputFolder);
if (!folder.exists()) {
Files.createDirectories(folder.toPath());
}
String parentFolder = folder.getParentFile().getAbsolutePath();
Set<String> originals = new HashSet<>();
List<Element> files = root.getChildren("file");
Iterator<Element> it = files.iterator();
while (it.hasNext()) {
String original = it.next().getAttributeValue("original");
if (original.isEmpty()) {
throw new IOException("<file> without \"original\" attribute");
}
originals.add(original);
}
Iterator<String> ot = originals.iterator();
XMLOutputter outputter = new XMLOutputter();
outputter.preserveSpace(true);
while (ot.hasNext()) {
String original = ot.next();
Set<String> skeletons = new HashSet<>();
Document newDoc = new Document(null, "xliff", null);
Element newRoot = newDoc.getRootElement();
newRoot.setAttributes(root.getAttributes());
for (int i = 0; i < files.size(); i++) {
Element file = files.get(i);
if (file.getAttributeValue("original").equals(original)) {
Element skeleton = file.getChild("skeleton");
String href = skeleton.getAttributeValue("href");
if (!skeletons.contains(href)) {
skeleton.addContent(Utils.encodeFromFile(new File(href).getAbsolutePath()));
skeleton.removeAttribute("href");
skeletons.add(href);
} else {
skeleton.setAttribute("href",Utils.makeRelativePath(parentFolder, href));
}
newRoot.addContent("\n");
newRoot.addContent(file);
}
}
newRoot.addContent("\n");
File xliffFile = new File(folder, original + ".xlf");
result.add(xliffFile.getAbsolutePath());
try (FileOutputStream out = new FileOutputStream(xliffFile)) {
outputter.output(newDoc, out);
}
}
return result;
}
}
30 changes: 22 additions & 8 deletions src/com/maxprograms/swordfish/xliff/XliffStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

import javax.xml.parsers.ParserConfigurationException;

import com.maxprograms.converters.Join;
import com.maxprograms.converters.Merge;
import com.maxprograms.languages.Language;
import com.maxprograms.languages.LanguageUtils;
Expand Down Expand Up @@ -132,7 +133,6 @@ public class XliffStore {
private String currentFile;
private String currentUnit;
private String state;
// private boolean translate;
private int tagCount;

private String srcLang;
Expand Down Expand Up @@ -1799,9 +1799,23 @@ public synchronized JSONArray getTaggedtMatches(JSONObject json)
}

public void exportXliff(String output)
throws SAXException, IOException, ParserConfigurationException, SQLException, URISyntaxException {
throws SAXException, IOException, ParserConfigurationException, SQLException {
updateXliff();
Skeletons.embedSkeletons(xliffFile, output);
File projectFolder = new File(xliffFile).getParentFile();
File tempFolder = new File(projectFolder, "tmp");
if (tempFolder.exists()) {
TmsServer.deleteFolder(tempFolder.getAbsolutePath());
}
List<String> files = Split.split(xliffFile, tempFolder.getAbsolutePath());
File tempFile = File.createTempFile("joined", ".xlf", tempFolder);
Join.join(files, tempFile.getAbsolutePath());
File outputFile = new File(output);
if (outputFile.exists()) {
Files.delete(outputFile.toPath());
}
Files.copy(tempFile.toPath(), outputFile.toPath());
Files.delete(tempFile.toPath());
TmsServer.deleteFolder(tempFolder.getAbsolutePath());
}

public void exportTMX(String output, String description, String client, String subject)
Expand Down Expand Up @@ -2195,10 +2209,10 @@ 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");
Element e = it.next();
String dataRef = e.getAttributeValue("dataRef");
if (!dataRef.isEmpty() && !references.contains(dataRef)) {
tag.removeAttribute("dataRef");
e.removeAttribute("dataRef");
}
}
}
Expand Down Expand Up @@ -2431,7 +2445,7 @@ public int tmTranslateAll(String memory, int penalization, Map<String, JSONObjec
array.put(json);
processed++;
if (processed % 20 == 0) {
int percentage = Math.round(processed * 100 / total);
int percentage = Math.round(processed * 100f / total);
if (percentage == 100) {
percentage = 99;
}
Expand Down Expand Up @@ -3894,7 +3908,7 @@ public static List<String> cjkWordList(String string, String separator) {
}

public String exportHTML(String title)
throws SQLException, IOException, SAXException, ParserConfigurationException, DataFormatException {
throws SQLException, IOException, SAXException, ParserConfigurationException {
File output = new File(xliffFile + ".html");
try (FileOutputStream out = new FileOutputStream(output)) {
writeString(out, "<html>\n");
Expand Down
3 changes: 0 additions & 3 deletions src/com/maxprograms/swordfish/xliff/XliffUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,6 @@ public static JSONObject getProjectDetails(File xliffFile) throws IOException {
if (skeleton == null) {
throw new IOException(NOTSWORDFISH);
}
if (!skeleton.getAttributeValue("href").isEmpty()) {
throw new IOException(NOTSWORDFISH);
}
Element metadata = file.getChild("mda:metadata");
if (metadata == null) {
throw new IOException(NOTSWORDFISH);
Expand Down
21 changes: 12 additions & 9 deletions ts/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,10 @@ class Swordfish {
Swordfish.mainWindow.webContents.send('set-theme', Swordfish.currentCss);
}
});
ipcMain.on('get-projects', (event: IpcMainEvent, arg: any) => {
ipcMain.on('get-projects', (event: IpcMainEvent) => {
Swordfish.getProjects(event);
});
ipcMain.on('get-memories', (event: IpcMainEvent, arg: any) => {
ipcMain.on('get-memories', (event: IpcMainEvent) => {
Swordfish.getMemories(event);
});
ipcMain.on('show-add-file', () => {
Expand All @@ -257,7 +257,7 @@ class Swordfish {
ipcMain.on('export-open-project', (event: IpcMainEvent, arg: any) => {
Swordfish.exportOpenProject(arg);
});
ipcMain.on('get-theme', (event: IpcMainEvent, arg: any) => {
ipcMain.on('get-theme', (event: IpcMainEvent) => {
event.sender.send('set-theme', Swordfish.currentCss);
});
ipcMain.on('serverSettings-height', (event: IpcMainEvent, arg: any) => {
Expand All @@ -272,7 +272,7 @@ class Swordfish {
ipcMain.on('browseDatabases-height', (event: IpcMainEvent, arg: any) => {
Swordfish.setHeight(Swordfish.browseDatabasesWindow, arg);
});
ipcMain.on('get-databases', (event: IpcMainEvent, arg: any) => {
ipcMain.on('get-databases', (event: IpcMainEvent) => {
event.sender.send('set-databases', Swordfish.remoteTmParams);
});
ipcMain.on('show-server-settings', (event: IpcMainEvent, arg: any) => {
Expand Down Expand Up @@ -396,7 +396,7 @@ class Swordfish {
ipcMain.on('close-addGlossary', () => {
Swordfish.destroyWindow(Swordfish.addGlossaryWindow);
});
ipcMain.on('get-glossaries', (event: IpcMainEvent, arg: any) => {
ipcMain.on('get-glossaries', (event: IpcMainEvent) => {
Swordfish.getGlossaries(event);
});
ipcMain.on('remove-glossaries', (event: IpcMainEvent, arg: any) => {
Expand Down Expand Up @@ -429,7 +429,7 @@ class Swordfish {
ipcMain.on('import-glossary-height', (event: IpcMainEvent, arg: any) => {
Swordfish.setHeight(Swordfish.importGlossaryWindow, arg);
});
ipcMain.on('get-glossary-file', (event: IpcMainEvent, arg: any) => {
ipcMain.on('get-glossary-file', (event: IpcMainEvent) => {
Swordfish.getGlossaryFile(event);
});
ipcMain.on('import-glossary-file', (event: IpcMainEvent, arg: any) => {
Expand Down Expand Up @@ -1061,6 +1061,9 @@ class Swordfish {
new MenuItem({ type: 'separator' }),
new MenuItem({ label: 'Toggle Full Screen', role: 'togglefullscreen' })
]);
if (!app.isPackaged) {
viewMenu.append(new MenuItem({ label: 'Open Development Tools', accelerator: 'F12', click: () => { Swordfish.mainWindow.webContents.openDevTools() } }));
}
let projectsMenu: Menu = Menu.buildFromTemplate([
{ label: 'New Project', accelerator: 'CmdOrCtrl+N', click: () => { Swordfish.addProject(); } },
{ label: 'Translate Projects', click: () => { Swordfish.translateProjects(); } },
Expand Down Expand Up @@ -1510,12 +1513,12 @@ class Swordfish {
let fileName: string = file.file;
if (fileName.endsWith('.sdlppx')) {
return {
defaultPath: fileName.substr(0, fileName.lastIndexOf('.')) + '.sdlrpx',
defaultPath: fileName.substring(0, fileName.lastIndexOf('.')) + '.sdlrpx',
filters: [{ name: file.type, extensions: 'sdlrpx' }, { name: 'Any File', extensions: '*' }]
}
}
let name = fileName.substr(0, fileName.lastIndexOf('.'));
let extension = fileName.substr(fileName.lastIndexOf('.'));
let name = fileName.substring(0, fileName.lastIndexOf('.'));
let extension = fileName.substring(fileName.lastIndexOf('.'));
return {
defaultPath: name + '_' + lang + extension,
filters: [{ name: file.type, extensions: extension }, { name: 'Any File', extensions: '*' }]
Expand Down
Loading

0 comments on commit f69fc55

Please sign in to comment.