Skip to content

Commit

Permalink
Updated for release 4.16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rmraya committed Apr 23, 2022
1 parent 8bba3ab commit 66f5aa8
Show file tree
Hide file tree
Showing 13 changed files with 243 additions and 158 deletions.
2 changes: 1 addition & 1 deletion html/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<h2 class="center">Swordfish IV</h2>
<div class="fill_width center">
<img src="../icons/icon.png" alt="about box">
<p>Copyright &copy; 2007 - 2021 Maxprograms</p>
<p>Copyright &copy; 2007 - 2022 Maxprograms</p>
</div>
<div class="buttonArea">
<button id="system">System Information</button>
Expand Down
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.15.0",
"version": "4.16.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.1.0",
"typescript": "^4.5.5"
"electron": "^18.1.0",
"typescript": "^4.6.3"
}
}
63 changes: 63 additions & 0 deletions src/com/maxprograms/swordfish/CheckURL.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*******************************************************************************
* 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;

import java.io.IOException;
import java.lang.System.Logger;
import java.lang.System.Logger.Level;
import java.net.HttpURLConnection;
import java.net.URL;

public class CheckURL {

protected static final Logger LOGGER = System.getLogger(CheckURL.class.getName());

public static void main(String[] args) {
if (args.length < 1) {
return;
}
checkURL(args[0]);
}

protected static void checkURL(String string) {
boolean waiting = true;
int count = 0;
while (waiting && count < 40) {
try {
connect(string);
waiting = false;
} catch (IOException e) {
try {
Thread.sleep(500);
count++;
} catch (InterruptedException e1) {
LOGGER.log(Level.ERROR, e1.getMessage(), e1);
Thread.currentThread().interrupt();
}
}
}
if (count < 40) {
LOGGER.log(Level.INFO, "ready");
} else {
System.exit(1);
}
}

private static void connect(String string) throws IOException {
URL url = new URL(string);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setConnectTimeout(1000);
connection.connect();
}

}
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.15.0";
public static final String BUILD = "20220302_1504";
public static final String VERSION = "4.16.0";
public static final String BUILD = "20220423_0737";

public static final String REASON = "reason";
public static final String STATUS = "status";
Expand Down
38 changes: 30 additions & 8 deletions src/com/maxprograms/swordfish/ProjectsHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ public void run() {
if (applyTM) {
XliffStore store = new XliffStore(p.getXliff(), p.getSourceLang().getCode(),
p.getTargetLang().getCode());
store.tmTranslateAll(memory, 0);
store.tmTranslateAll(memory, 0, processes, id);
}
if (searchTerms) {
XliffStore store = new XliffStore(p.getXliff(), p.getSourceLang().getCode(),
Expand Down Expand Up @@ -1022,19 +1022,41 @@ private JSONObject tmTranslateAll(String request) {
JSONObject json = new JSONObject(request);
String project = json.getString("project");
String memory = json.getString("memory");
int penalization = 0;
if (json.has("penalization")) {
penalization = json.getInt("penalization");
}
int penalization = json.has("penalization") ? json.getInt("penalization") : 0;
if (!projectStores.containsKey(project)) {
Project prj = projects.get(project);
XliffStore store = new XliffStore(prj.getXliff(), prj.getSourceLang().getCode(),
prj.getTargetLang().getCode());
projectStores.put(project, store);
}
result.put("translated", projectStores.get(project).tmTranslateAll(memory, penalization));
} catch (IOException | SQLException | JSONException | SAXException | ParserConfigurationException
| URISyntaxException e) {
String id = "" + System.currentTimeMillis();
result.put("process", id);
if (processes == null) {
processes = new Hashtable<>();
}
JSONObject obj = new JSONObject();
obj.put("percentage", 0);
obj.put(Constants.PROGRESS, Constants.PROCESSING);
processes.put(id, obj);
Thread thread = new Thread() {
@Override
public void run() {
try {
obj.put("translated",
projectStores.get(project).tmTranslateAll(memory, penalization, processes, id));
obj.put(Constants.PROGRESS, Constants.COMPLETED);
processes.put(id, obj);
} catch (JSONException | IOException | SQLException | SAXException
| ParserConfigurationException e) {
logger.log(Level.WARNING, e.getMessage(), e);
obj.put(Constants.PROGRESS, Constants.ERROR);
obj.put(Constants.REASON, e.getMessage());
processes.put(id, obj);
}
}
};
thread.start();
} catch (Exception e) {
logger.log(Level.ERROR, e.getMessage(), e);
result.put(Constants.REASON, e.getMessage());
}
Expand Down
3 changes: 3 additions & 0 deletions src/com/maxprograms/swordfish/RemoteUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ public static JSONArray getRemoteMemories(String server, String ticket) throws I
}

public static String getTicket(String server, String user, String password) throws IOException {
if (server.endsWith("/")) {
server = server.substring(0, server.length() - 1);
}
URL serverUrl = new URL(server + "/remote");
HttpsURLConnection connection = (HttpsURLConnection) serverUrl.openConnection();
connection.setRequestMethod("GET");
Expand Down
3 changes: 2 additions & 1 deletion src/com/maxprograms/swordfish/ServicesHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,8 @@ 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
4 changes: 0 additions & 4 deletions src/com/maxprograms/swordfish/TmsServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,6 @@ public void handle(HttpExchange t) throws IOException {
try (DataOutputStream stream = new DataOutputStream(t.getResponseBody())) {
stream.writeBytes(response);
}
if ("stop".equals(command)) {
server.stop(0);
System.exit(0);
}
} catch (IOException | SQLException e) {
logger.log(Level.ERROR, e);
obj.put(Constants.STATUS, Constants.ERROR);
Expand Down
4 changes: 2 additions & 2 deletions src/com/maxprograms/swordfish/tm/InternalDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,8 @@ public List<Element> concordanceSearch(String searchStr, String srcLang, int lim
} else {
String sql = caseSensitive ? "SELECT tuid, puretext FROM tuv WHERE lang=? AND puretext LIKE ? LIMIT ?"
: "SELECT tuid, puretext FROM tuv WHERE lang=? AND puretext ILIKE ? LIMIT ?";
String escaped = searchStr.replace("%", "\\%").replace("_", "\\_");
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
String escaped = searchStr.replace("%", "\\%").replace("_", "\\_");
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1, srcLang);
stmt.setString(2, "%" + escaped + "%");
stmt.setInt(3, limit);
Expand Down
5 changes: 4 additions & 1 deletion src/com/maxprograms/swordfish/tm/RemoteDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ public class RemoteDatabase implements ITmEngine {
private SAXBuilder builder;

public RemoteDatabase(String server, String user, String password, String dbname) throws IOException {
this.server = server;
if (server.endsWith("/")) {
server = server.substring(0, server.length() - 1);
}
this.server = server.strip();
this.dbname = dbname;
builder = new SAXBuilder();
ticket = RemoteUtils.getTicket(server, user, password);
Expand Down
21 changes: 19 additions & 2 deletions src/com/maxprograms/swordfish/xliff/XliffStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -2398,13 +2398,21 @@ public JSONArray tmTranslate(JSONObject json)
return getTaggedtMatches(json);
}

public int tmTranslateAll(String memory, int penalization)
public int tmTranslateAll(String memory, int penalization, Map<String, JSONObject> processes, String processId)
throws IOException, SQLException, SAXException, ParserConfigurationException {
String memoryName = MemoriesHandler.getName(memory);
MemoriesHandler.open(memory);
ITmEngine engine = MemoriesHandler.getEngine(memory);
String sql = "SELECT file, unitId, segId, source, sourceText, target FROM segments WHERE state <> 'final'";
String sql = "SELECT COUNT(*) FROM segments WHERE type = 'S' AND state <> 'final'";
int total = 0;
try (ResultSet rs = stmt.executeQuery(sql)) {
while (rs.next()) {
total = rs.getInt(1);
}
}
sql = "SELECT file, unitId, segId, source, sourceText, target FROM segments WHERE type = 'S' AND state <> 'final'";
int count = 0;
int processed = 0;
try (ResultSet rs = stmt.executeQuery(sql)) {
JSONObject params = new JSONObject();
params.put("srcLang", srcLang);
Expand All @@ -2421,6 +2429,14 @@ public int tmTranslateAll(String memory, int penalization)
json.put("segment", segment);
json.put("pure", pure);
array.put(json);
processed++;
if (processed % 20 == 0) {
int percentage = Math.round(processed * 100 / total);
if (percentage == 100) {
percentage = 99;
}
processes.get(processId).put("percentage", percentage);
}
if (array.length() == 250) {
params.put("segments", array);
JSONArray translations = engine.batchTranslate(params);
Expand All @@ -2431,6 +2447,7 @@ public int tmTranslateAll(String memory, int penalization)
params.put("segments", array);
JSONArray translations = engine.batchTranslate(params);
count += storeMatches(translations, memoryName, penalization);
processes.get(processId).put("percentage", 100);
}
MemoriesHandler.close(memory);
return count;
Expand Down
Loading

0 comments on commit 66f5aa8

Please sign in to comment.