Skip to content

Commit

Permalink
Updated for release 3.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
rmraya committed Apr 16, 2024
1 parent ddb0bd0 commit 6f8fc21
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 42 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "tmxeditor",
"productName": "TMXEditor",
"version": "3.1.0",
"version": "3.1.1",
"description": "TMX Editor",
"main": "js/app.js",
"scripts": {
Expand All @@ -19,8 +19,8 @@
"url": "https://github.com/rmraya/TMXEditor.git"
},
"devDependencies": {
"electron": "^29.1.5",
"typescript": "^5.4.3"
"electron": "^29.3.0",
"typescript": "^5.4.5"
},
"dependencies": {
"typesxml": "^1.3.0",
Expand Down
4 changes: 2 additions & 2 deletions src/com/maxprograms/tmxserver/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 = "TMXEditor";
public static final String VERSION = "3.1.0";
public static final String BUILD = "20240325_1157";
public static final String VERSION = "3.1.1";
public static final String BUILD = "20240411_0806";

public static final String REASON = "reason";
public static final String STATUS = "status";
Expand Down
10 changes: 9 additions & 1 deletion src/com/maxprograms/tmxserver/TMXServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ public TMXServer(Integer port) throws IOException {
server.createContext("/TMXServer", this);
server.setExecutor(new ThreadPoolExecutor(3, 10, 20, TimeUnit.SECONDS, new ArrayBlockingQueue<>(100)));
service = new TMXService();

Thread closeHook = new Thread(() -> {
if (service.isOpen()) {
service.closeFile();
}
});
Runtime.getRuntime().addShutdownHook(closeHook);
}

public static void main(String[] args) {
Expand Down Expand Up @@ -732,7 +739,8 @@ private static String getSystemInformation() {
result.put("xmljava", mf1
.format(new String[] { com.maxprograms.xml.Constants.VERSION, com.maxprograms.xml.Constants.BUILD }));
result.put("bcp47j", mf1
.format(new String[] { com.maxprograms.languages.Constants.VERSION, com.maxprograms.languages.Constants.BUILD }));
.format(new String[] { com.maxprograms.languages.Constants.VERSION,
com.maxprograms.languages.Constants.BUILD }));
MessageFormat mf2 = new MessageFormat(Messages.getString("TMXServer.3"));
result.put("java",
mf2.format(new String[] { System.getProperty("java.version"), System.getProperty("java.vendor") }));
Expand Down
25 changes: 21 additions & 4 deletions src/com/maxprograms/tmxserver/TMXService.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,24 @@ public JSONObject getLanguages() throws JSONException, IOException, SAXException
String code = it.next();
JSONObject json = new JSONObject();
json.put("code", code);
json.put("name", LanguageUtils.getLanguage(code).getDescription());
String description = LanguageUtils.getLanguage(code).getDescription();
if (description.isEmpty()) {
// try guessing the language
code = code.replace("_", "-");
if (code.indexOf("-") != -1) {
String[] parts = code.split("-");
Language language = LanguageUtils.getLanguage(parts[0]);
if (!language.getDescription().isEmpty()) {
MessageFormat mf = new MessageFormat(Messages.getString("TMXService.13"));
description = mf.format(new String[] { language.getDescription() });
} else {
description = Messages.getString("TMXService.14");
}
} else {
description = Messages.getString("TMXService.14");
}
}
json.put("name", description);
data.put(json);
}
result.put("languages", data);
Expand Down Expand Up @@ -925,9 +942,9 @@ public JSONObject mergeFiles(String merged, List<String> files) {
header.setAttribute("srclang", "*all*");
out.write(
("""
<?xml version=\"1.0\" ?>
<!DOCTYPE tmx PUBLIC \"-//LISA OSCAR:1998//DTD for Translation Memory eXchange//EN\" \"tmx14.dtd\">
<tmx version=\"1.4\">
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tmx PUBLIC "-//LISA OSCAR:1998//DTD for Translation Memory eXchange//EN" "tmx14.dtd">
<tmx version="1.4">
""")
.getBytes(StandardCharsets.UTF_8));
out.write((TextUtils.padding(1, indentation) + header.toString() + "\n")
Expand Down
15 changes: 11 additions & 4 deletions src/com/maxprograms/tmxserver/excel/ExcelWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@

import com.maxprograms.xml.Document;
import com.maxprograms.xml.Element;
import com.maxprograms.xml.Indenter;
import com.maxprograms.xml.SAXBuilder;
import com.maxprograms.xml.XMLOutputter;

Expand Down Expand Up @@ -88,7 +87,6 @@ private void setSheetName(File folder, String name) throws SAXException, IOExcep
try (FileOutputStream out = new FileOutputStream(workbook)) {
XMLOutputter outputter = new XMLOutputter();
outputter.preserveSpace(true);
Indenter.indent(root, 2);
outputter.output(doc, out);
}
}
Expand All @@ -101,6 +99,16 @@ private void setStrings(File folder, Sheet sheet) throws SAXException, IOExcepti

File sheetXml = new File(folder, "xl" + SEP + "worksheets" + SEP + "sheet1.xml");
Document sheetDoc = builder.build(sheetXml);
Element columns = sheetDoc.getRootElement().getChild("cols");
columns.setContent(new ArrayList<>());
for (int i = 0; i < sheet.getColumns().size(); i++) {
Element col = new Element("col");
col.setAttribute("min", "" + (i + 1));
col.setAttribute("max", "" + (i + 1));
col.setAttribute("width", "80");
col.setAttribute("customWidth", "1");
columns.addContent(col);
}
Element sheetData = sheetDoc.getRootElement().getChild("sheetData");
sheetData.setContent(new ArrayList<>());

Expand Down Expand Up @@ -136,6 +144,7 @@ private void setStrings(File folder, Sheet sheet) throws SAXException, IOExcepti
Element c = new Element("c");
c.setAttribute("r", columnIndex.get(colCount) + (i + 1));
c.setAttribute("t", "s");
c.setAttribute("s", "1");
Element v = new Element("v");
v.addContent("" + unique.get(cell));
c.addContent(v);
Expand All @@ -153,13 +162,11 @@ private void setStrings(File folder, Sheet sheet) throws SAXException, IOExcepti
try (FileOutputStream out = new FileOutputStream(sharedStrings)) {
XMLOutputter outputter = new XMLOutputter();
outputter.preserveSpace(true);
Indenter.indent(sst, 2);
outputter.output(stringsDoc, out);
}
try (FileOutputStream out = new FileOutputStream(sheetXml)) {
XMLOutputter outputter = new XMLOutputter();
outputter.preserveSpace(true);
Indenter.indent(sheetDoc.getRootElement(), 2);
outputter.output(sheetDoc, out);
}
}
Expand Down
Binary file modified src/com/maxprograms/tmxserver/excel/template.xlsx
Binary file not shown.
8 changes: 4 additions & 4 deletions src/com/maxprograms/tmxserver/tmx/SplitStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ private void createFile() throws IOException {
String newFile = name.substring(0, name.length() - 4) + "_" + fileCount + ".tmx";
out = new FileOutputStream(new File(newFile));
writeString("""
<?xml version=\"1.0\" ?>
<!DOCTYPE tmx PUBLIC \"-//LISA OSCAR:1998//DTD for Translation Memory eXchange//EN\" \"tmx14.dtd\">
<tmx version=\"1.4\">
""");
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tmx PUBLIC "-//LISA OSCAR:1998//DTD for Translation Memory eXchange//EN" "tmx14.dtd">
<tmx version="1.4">
""");
writeString(TextUtils.padding(1, indentation) + header.toString() + "\n");
writeString(TextUtils.padding(1, indentation) + "<body>\n");
fileCount++;
Expand Down
14 changes: 4 additions & 10 deletions src/com/maxprograms/tmxserver/tmx/SqlStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.Vector;
import java.util.regex.Pattern;

import javax.xml.parsers.ParserConfigurationException;
Expand All @@ -40,7 +40,6 @@
import org.xml.sax.SAXException;

import com.maxprograms.languages.Language;
import com.maxprograms.languages.LanguageUtils;
import com.maxprograms.tmxserver.Constants;
import com.maxprograms.tmxserver.excel.ExcelWriter;
import com.maxprograms.tmxserver.excel.Sheet;
Expand Down Expand Up @@ -154,10 +153,6 @@ public void storeTU(Element tu) throws IOException, SQLException {
// ignore this one
continue;
}
lang = LanguageUtils.normalizeCode(lang);
if (!languages.contains(lang)) {
languages.add(lang);
}
if (tuvCount == 0) {
storeTUV(id, lang, tuv);
} else {
Expand Down Expand Up @@ -410,9 +405,9 @@ public void writeFile(File file) throws IOException, SAXException, ParserConfigu
saved = 0l;
try (FileOutputStream out = new FileOutputStream(file)) {
writeString(out, """
<?xml version=\"1.0\" ?>
<!DOCTYPE tmx PUBLIC \"-//LISA OSCAR:1998//DTD for Translation Memory eXchange//EN\" \"tmx14.dtd\">
<tmx version=\"1.4\">
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tmx PUBLIC "-//LISA OSCAR:1998//DTD for Translation Memory eXchange//EN" "tmx14.dtd">
<tmx version="1.4">
""");

writeString(out, TextUtils.padding(1, indentation) + header.toString() + "\n");
Expand Down Expand Up @@ -1014,7 +1009,6 @@ public void exportDelimited(String file)
while (langIt.hasNext()) {
String lang = langIt.next();
String pure = getPure(tuid, lang);
// Element tuv = getTuv(tuid, lang);
String text = " ";
if (!pure.isEmpty()) {
text = TmxUtils.cleanLines(pure);
Expand Down
2 changes: 2 additions & 0 deletions src/com/maxprograms/tmxserver/tmxserver.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ TMXService.1=Error getting languages from store
TMXService.10=Error reading CSV file
TMXService.11=Error getting languages
TMXService.12=Error checking CSV languages
TMXService.13={0} (Unknown Variant)
TMXService.14=Unknown Language
TMXService.2=Null Store
TMXService.3=File does not exist
TMXService.4=Error splitting files
Expand Down
2 changes: 2 additions & 0 deletions src/com/maxprograms/tmxserver/tmxserver_es.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ TMXService.1=Error al obtener idiomas desde el almacenamiento
TMXService.10=Error al leer el archivo CSV
TMXService.11=Error al obtener idiomas
TMXService.12=Error al comprobar los idiomas CSV
TMXService.13={0} (Variante Desconocida)
TMXService.14=Idioma Desconocido
TMXService.2=Almacenamiento nulo
TMXService.3=El archivo no existe
TMXService.4=Error al dividir archivos
Expand Down
19 changes: 7 additions & 12 deletions ts/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1244,7 +1244,11 @@ class App {
let title = '';
switch (arg.type) {
case 'TMXEditor':
licenseFile = 'file://' + path.join(app.getAppPath(), 'html', 'licenses', 'EclipsePublicLicense1.0.html');
case "BCP47J":
case "XMLJava":
case "sdltm":
case "TMXValidator":
case "typesxml": licenseFile = 'file://' + path.join(app.getAppPath(), 'html', 'licenses', 'EclipsePublicLicense1.0.html');
title = 'Eclipse Public License 1.0';
break;
case "electron":
Expand All @@ -1253,7 +1257,7 @@ class App {
break;
case "SLF4J":
licenseFile = 'file://' + path.join(app.getAppPath(), 'html', 'licenses', 'slf4j.txt');
title = 'Apache 2.0';
title = 'MIT License';
break;
case "SQLite":
licenseFile = 'file://' + path.join(app.getAppPath(), 'html', 'licenses', 'Apache2.0.html');
Expand All @@ -1263,14 +1267,6 @@ class App {
licenseFile = 'file://' + path.join(app.getAppPath(), 'html', 'licenses', 'java.html');
title = 'GPL2 with Classpath Exception';
break;
case "BCP47J":
case "XMLJava":
case "sdltm":
case "TMXValidator":
case "typesxml":
licenseFile = 'file://' + path.join(app.getAppPath(), 'html', 'licenses', 'EclipsePublicLicense1.0.html');
title = 'Eclipse Public License 1.0';
break;
case "JSON":
licenseFile = 'file://' + path.join(app.getAppPath(), 'html', 'licenses', 'json.txt');
title = 'JSON.org License';
Expand Down Expand Up @@ -1588,7 +1584,6 @@ class App {
writeFile(path.join(app.getPath('appData'), app.name, 'recent.json'), JSON.stringify(jsonData, undefined, 4), (error) => {
if (error instanceof Error) {
App.showMessage({ type: 'error', message: error.message });
return;
}
});
});
Expand Down Expand Up @@ -1942,7 +1937,7 @@ class App {
if (App.needsName) {
App.saveAs();
return;
}
}
if (App.editingCell.id) {
App.mainWindow.webContents.send('force-save');
let intervalObject = setInterval(() => {
Expand Down
4 changes: 2 additions & 2 deletions ts/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Main {
currentContent: string;
selectedUnits: string[] = [];

static EDIT: string = '<svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">' +
static readonly EDIT: string = '<svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">' +
'<path d="M2.25 15.75H5.0625L13.3575 7.45502L10.545 4.64252L2.25 12.9375V15.75ZM3.75 13.56L10.545 6.76502L11.235 7.45502L4.44 14.25H3.75V13.56Z" />' +
'<path d="M13.7775 2.46751C13.485 2.17501 13.0125 2.17501 12.72 2.46751L11.3475 3.84001L14.16 6.65251L15.5325 5.28001C15.825 4.98751 15.825 4.51501 15.5325 4.22251L13.7775 2.46751Z" />' +
'</svg>';
Expand Down Expand Up @@ -820,7 +820,7 @@ class Main {
this.currentContent = this.currentCell.innerHTML;
this.currentCell.contentEditable = 'false';
this.currentCell.classList.remove('editing');
this.electron.ipcRenderer.send('saved-edit',{ id: this.currentId, lang: this.currentLang });
this.electron.ipcRenderer.send('saved-edit', { id: this.currentId, lang: this.currentLang });
this.currentCell = null;
}
}
Expand Down

0 comments on commit 6f8fc21

Please sign in to comment.