diff --git a/jars/openxliff.jar b/jars/openxliff.jar index 4981c1b..c5fc6fa 100644 Binary files a/jars/openxliff.jar and b/jars/openxliff.jar differ diff --git a/package.json b/package.json index 7b8bd46..d1f8930 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -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" } } diff --git a/src/com/maxprograms/swordfish/Constants.java b/src/com/maxprograms/swordfish/Constants.java index edf28aa..11b3c6a 100644 --- a/src/com/maxprograms/swordfish/Constants.java +++ b/src/com/maxprograms/swordfish/Constants.java @@ -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"; diff --git a/src/com/maxprograms/swordfish/ProjectsHandler.java b/src/com/maxprograms/swordfish/ProjectsHandler.java index 1b1a32e..21a1753 100644 --- a/src/com/maxprograms/swordfish/ProjectsHandler.java +++ b/src/com/maxprograms/swordfish/ProjectsHandler.java @@ -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()); @@ -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()); } diff --git a/src/com/maxprograms/swordfish/ServicesHandler.java b/src/com/maxprograms/swordfish/ServicesHandler.java index 88c5736..b79f79a 100644 --- a/src/com/maxprograms/swordfish/ServicesHandler.java +++ b/src/com/maxprograms/swordfish/ServicesHandler.java @@ -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; } diff --git a/src/com/maxprograms/swordfish/tm/InternalDatabase.java b/src/com/maxprograms/swordfish/tm/InternalDatabase.java index b125aa9..e0588bb 100755 --- a/src/com/maxprograms/swordfish/tm/InternalDatabase.java +++ b/src/com/maxprograms/swordfish/tm/InternalDatabase.java @@ -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; @@ -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) { @@ -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()) { @@ -722,5 +728,4 @@ public JSONArray batchTranslate(JSONObject params) } return result; } - } diff --git a/src/com/maxprograms/swordfish/xliff/Skeletons.java b/src/com/maxprograms/swordfish/xliff/Skeletons.java index 4b8b6cf..d9cb6e2 100644 --- a/src/com/maxprograms/swordfish/xliff/Skeletons.java +++ b/src/com/maxprograms/swordfish/xliff/Skeletons.java @@ -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 files = xliff.getChildren("file"); - Iterator 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(); @@ -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<>()); diff --git a/src/com/maxprograms/swordfish/xliff/Split.java b/src/com/maxprograms/swordfish/xliff/Split.java new file mode 100644 index 0000000..3078a79 --- /dev/null +++ b/src/com/maxprograms/swordfish/xliff/Split.java @@ -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 split(String xliff, String outputFolder) + throws SAXException, IOException, ParserConfigurationException { + List 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 originals = new HashSet<>(); + List files = root.getChildren("file"); + Iterator it = files.iterator(); + while (it.hasNext()) { + String original = it.next().getAttributeValue("original"); + if (original.isEmpty()) { + throw new IOException(" without \"original\" attribute"); + } + originals.add(original); + } + Iterator ot = originals.iterator(); + XMLOutputter outputter = new XMLOutputter(); + outputter.preserveSpace(true); + while (ot.hasNext()) { + String original = ot.next(); + Set 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; + } +} diff --git a/src/com/maxprograms/swordfish/xliff/XliffStore.java b/src/com/maxprograms/swordfish/xliff/XliffStore.java index b90c7e3..4a8a89e 100644 --- a/src/com/maxprograms/swordfish/xliff/XliffStore.java +++ b/src/com/maxprograms/swordfish/xliff/XliffStore.java @@ -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; @@ -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; @@ -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 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) @@ -2195,10 +2209,10 @@ private void removeMissingReferences(Element child, Set references) { List tags = child.getChildren(); Iterator 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"); } } } @@ -2431,7 +2445,7 @@ public int tmTranslateAll(String memory, int penalization, Map 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, "\n"); diff --git a/src/com/maxprograms/swordfish/xliff/XliffUtils.java b/src/com/maxprograms/swordfish/xliff/XliffUtils.java index 3a8710a..5dad0e0 100644 --- a/src/com/maxprograms/swordfish/xliff/XliffUtils.java +++ b/src/com/maxprograms/swordfish/xliff/XliffUtils.java @@ -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); diff --git a/ts/App.ts b/ts/App.ts index 6344d4e..6e029a5 100644 --- a/ts/App.ts +++ b/ts/App.ts @@ -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', () => { @@ -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) => { @@ -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) => { @@ -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) => { @@ -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) => { @@ -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(); } }, @@ -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: '*' }] diff --git a/ts/Main.ts b/ts/Main.ts index be52173..b7790bc 100644 --- a/ts/Main.ts +++ b/ts/Main.ts @@ -90,10 +90,10 @@ class Main { Main.electron.ipcRenderer.on('remove-projects', () => { this.projectsView.removeProjects(); }); - Main.electron.ipcRenderer.on('export-translations', (event: Electron.IpcRendererEvent, arg: any) => { + Main.electron.ipcRenderer.on('export-translations', () => { this.exportTranslations(); }); - Main.electron.ipcRenderer.on('export-project', (event: Electron.IpcRendererEvent, arg: any) => { + Main.electron.ipcRenderer.on('export-project', () => { this.projectsView.exportProject(); }); Main.electron.ipcRenderer.on('export-translations-tmx', () => { @@ -159,10 +159,10 @@ class Main { Main.electron.ipcRenderer.on('term-search-requested', () => { this.searchTerm(); }); - Main.electron.ipcRenderer.on('apply-terminology', (event: Electron.IpcRendererEvent, arg: any) => { + Main.electron.ipcRenderer.on('apply-terminology', () => { this.applyTerminology(); }); - Main.electron.ipcRenderer.on('apply-terminology-all', (event: Electron.IpcRendererEvent, arg: any) => { + Main.electron.ipcRenderer.on('apply-terminology-all', () => { this.applyTerminologyAll(); }); Main.electron.ipcRenderer.on('add-term-requested', () => { @@ -399,7 +399,7 @@ class Main { setStatus(arg: any): void { let status: HTMLDivElement = document.getElementById('status') as HTMLDivElement; - status.innerText= arg; + status.innerText = arg; if (arg.length > 0) { status.style.display = 'block'; } else { diff --git a/ts/addFile.ts b/ts/addFile.ts index 645dbe5..e9ada52 100644 --- a/ts/addFile.ts +++ b/ts/addFile.ts @@ -95,8 +95,7 @@ class AddFile { setLanguages(arg: any): void { let array = arg.languages; let languageOptions = ''; - for (let i = 0; i < array.length; i++) { - let lang = array[i]; + for (let lang of array) { languageOptions = languageOptions + ''; } document.getElementById('srcLangSelect').innerHTML = languageOptions; @@ -107,9 +106,8 @@ class AddFile { setTypes(arg: any): void { this.typesOption = ''; - let length: number = arg.formats.length; - for (let i = 0; i < length; i++) { - this.typesOption = this.typesOption + ''; + for (let format of arg.formats) { + this.typesOption = this.typesOption + ''; } document.getElementById('typeSelect').innerHTML = this.typesOption; this.electron.ipcRenderer.send('get-charsets'); diff --git a/ts/addProject.ts b/ts/addProject.ts index bd92925..5d65d45 100644 --- a/ts/addProject.ts +++ b/ts/addProject.ts @@ -164,9 +164,8 @@ class AddProject { setSubjects(subjects: string[]): void { let options: string = ''; - let length: number = subjects.length; - for (let i = 0; i < length; i++) { - options = options + ''; + for (let subject of subjects) { + options = options + ''; } document.getElementById('subjects').innerHTML = options; } @@ -174,8 +173,7 @@ class AddProject { setLanguages(arg: any): void { let array = arg.languages; let languageOptions = ''; - for (let i = 0; i < array.length; i++) { - let lang = array[i]; + for (let lang of array) { languageOptions = languageOptions + ''; } document.getElementById('srcLangSelect').innerHTML = languageOptions; diff --git a/ts/addTerm.ts b/ts/addTerm.ts index 4fac86b..fe1d4b5 100644 --- a/ts/addTerm.ts +++ b/ts/addTerm.ts @@ -41,13 +41,13 @@ class AddTerm { this.electron.ipcRenderer.on('set-selected-text', (event: Electron.IpcRendererEvent, arg: any) => { this.setParams(arg); }); - document.getElementById('srcLangSelect').addEventListener('change', (ev: Event) => { + document.getElementById('srcLangSelect').addEventListener('change', () => { let code: string = (document.getElementById('srcLangSelect') as HTMLSelectElement).value; if (this.isBiDi(code)) { (document.getElementById('source') as HTMLInputElement).dir = 'rtl'; } }); - document.getElementById('tgtLangSelect').addEventListener('change', (ev: Event) => { + document.getElementById('tgtLangSelect').addEventListener('change', () => { let code: string = (document.getElementById('tgtLangSelect') as HTMLSelectElement).value; if (this.isBiDi(code)) { (document.getElementById('target') as HTMLInputElement).dir = 'rtl'; @@ -93,8 +93,7 @@ class AddTerm { setLanguages(arg: any): void { let array = arg.languages; let languageOptions = ''; - for (let i = 0; i < array.length; i++) { - let lang = array[i]; + for (let lang of array) { languageOptions = languageOptions + ''; } document.getElementById('srcLangSelect').innerHTML = languageOptions; diff --git a/ts/concordanceSearch.ts b/ts/concordanceSearch.ts index 442fd1f..754caec 100644 --- a/ts/concordanceSearch.ts +++ b/ts/concordanceSearch.ts @@ -46,7 +46,7 @@ class ConcordanceSearch { }); (document.getElementById('maxEntries') as HTMLSelectElement).value = '20'; (document.getElementById('searchText') as HTMLInputElement).focus(); - document.getElementById('languagesSelect').addEventListener('change', (ev: Event) => { + document.getElementById('languagesSelect').addEventListener('change', () => { let code: string = (document.getElementById('languagesSelect') as HTMLSelectElement).value; if (this.isBiDi(code)) { (document.getElementById('searchText') as HTMLInputElement).dir = 'rtl'; @@ -58,8 +58,7 @@ class ConcordanceSearch { setLanguages(arg: any): void { let array = arg.languages; let languageOptions = ''; - for (let i = 0; i < array.length; i++) { - let lang = array[i]; + for (let lang of array) { languageOptions = languageOptions + ''; } document.getElementById('languagesSelect').innerHTML = languageOptions; diff --git a/ts/defaultLangs.ts b/ts/defaultLangs.ts index 7724bcb..4a1aa4a 100644 --- a/ts/defaultLangs.ts +++ b/ts/defaultLangs.ts @@ -41,8 +41,7 @@ class DefaultLanguages { setLanguages(arg: any): void { let array = arg.languages; let languageOptions = ''; - for (let i = 0; i < array.length; i++) { - let lang = array[i]; + for (let lang of array) { languageOptions = languageOptions + ''; } document.getElementById('srcLangSelect').innerHTML = languageOptions; diff --git a/ts/divider.ts b/ts/divider.ts index 4bb6c12..f9877a6 100644 --- a/ts/divider.ts +++ b/ts/divider.ts @@ -33,7 +33,7 @@ class VerticalSplit { this.divider.classList.add('hdivider'); this.divider.draggable = true; this.divider.addEventListener('dragstart', (event: DragEvent) => { - this.dragStart(event); + this.dragStart(); }); this.divider.addEventListener('drag', (event: DragEvent) => { this.drag(event); @@ -86,7 +86,7 @@ class VerticalSplit { return this.right; } - dragStart(ev: DragEvent): void { + dragStart(): void { this.currentSum = this.left.clientWidth + this.right.clientWidth; } diff --git a/ts/filterConfig.ts b/ts/filterConfig.ts index af55085..65a7ad9 100644 --- a/ts/filterConfig.ts +++ b/ts/filterConfig.ts @@ -46,8 +46,7 @@ class FilterConfig { let tbody: HTMLTableSectionElement = document.getElementById('tbody') as HTMLTableSectionElement; tbody.innerHTML = ''; this.selected = new Map(); - for (let i = 0; i < children.length; i++) { - let tag: any = children[i]; + for (let tag of children) { let attributes: string[][] = tag.attributes; let tr: HTMLTableRowElement = document.createElement('tr'); tbody.appendChild(tr); @@ -135,8 +134,7 @@ class FilterConfig { } getAttribute(attributes: string[][], name: string, defaultValue: string): string { - for (let i = 0; i < attributes.length; i++) { - let attribute: string[] = attributes[i]; + for (let attribute of attributes) { if (attribute[0] === name) { return attribute[1]; } diff --git a/ts/locations.ts b/ts/locations.ts index 86a42fe..5fd0ac3 100644 --- a/ts/locations.ts +++ b/ts/locations.ts @@ -54,7 +54,7 @@ export class Locations { this.locations.forEach((value: Point, key: string) => { text = text + '\"' + key + '\": {\"x\":' + value.x + ', \"y\":' + value.y + '},'; }); - text = text.substr(0, text.length - 1) + '}' + text = text.substring(0, text.length - 1) + '}' let json = JSON.parse(text); writeFile(this.file, JSON.stringify(json), (err: Error) => { if (err) throw err; diff --git a/ts/preferences.ts b/ts/preferences.ts index 6b27b84..a5eae75 100644 --- a/ts/preferences.ts +++ b/ts/preferences.ts @@ -1192,8 +1192,7 @@ class Preferences { getOptions(array: any[]): string { let languageOptions = ''; - for (let i = 0; i < array.length; i++) { - let lang = array[i]; + for (let lang of array) { languageOptions = languageOptions + ''; } return languageOptions; @@ -1202,22 +1201,22 @@ class Preferences { setFilters(json: any): void { this.filtersTable.innerHTML = ''; let files: string[] = json.files; - for (let i = 0; i < files.length; i++) { + for (let file of files) { let row: HTMLTableRowElement = document.createElement('tr'); this.filtersTable.appendChild(row); let col1: HTMLTableCellElement = document.createElement('td'); col1.classList.add('middle'); row.appendChild(col1); let check: HTMLInputElement = document.createElement('input'); - check.id = 'ck_' + files[i]; + check.id = 'ck_' + file; check.type = 'checkbox'; col1.appendChild(check); row.addEventListener('click', (event: MouseEvent) => { - this.clicked(row, files[i], check); + this.clicked(row, file, check); }); let col2 = document.createElement('td'); col2.classList.add('fill_width'); - col2.innerText = files[i]; + col2.innerText = file; row.appendChild(col2); } this.selected.clear(); diff --git a/ts/projects.ts b/ts/projects.ts index 14c5159..23488ef 100644 --- a/ts/projects.ts +++ b/ts/projects.ts @@ -444,9 +444,9 @@ class ProjectsView { let projectId = arg.project; let svg = arg.statistics.svg; let rows: HTMLCollectionOf = this.tbody.getElementsByTagName('tr'); - for (let i = 0; i < rows.length; i++) { - if (rows[i].id === projectId) { - let cells: HTMLCollectionOf = rows[i].getElementsByTagName('td'); + for (let row of rows) { + if (row.id === projectId) { + let cells: HTMLCollectionOf = row.getElementsByTagName('td'); cells[2].innerHTML = svg; break; } diff --git a/ts/spaceAnalysis.ts b/ts/spaceAnalysis.ts index 7bef44f..fe61dae 100644 --- a/ts/spaceAnalysis.ts +++ b/ts/spaceAnalysis.ts @@ -87,8 +87,8 @@ class SpaceAnalysis { return; } let selectedRows: HTMLCollectionOf = document.getElementsByClassName('selected'); - for (let i = 0; i < selectedRows.length; i++) { - selectedRows[i].classList.remove('selected'); + for (let row of selectedRows) { + row.classList.remove('selected'); } tr.classList.add('selected'); } diff --git a/ts/tabs.ts b/ts/tabs.ts index 2554e00..70e8ded 100644 --- a/ts/tabs.ts +++ b/ts/tabs.ts @@ -29,7 +29,7 @@ class Tab { this.label.id = this.id; if (description.length > 40) { this.label.title = description; - this.label.innerText = '...' + description.substr(description.length - 37); + this.label.innerText = '...' + description.substring(description.length - 37); } else { this.label.innerText = description; } @@ -119,11 +119,11 @@ class TabHolder { } clear(): void { - this.labels.forEach((value, key) => { + this.labels.forEach((value) => { this.tabsHolder.removeChild(value); }); this.labels.clear(); - this.tabs.forEach((value, key) => { + this.tabs.forEach((value) => { this.contentHolder.removeChild(value.getContainer()); }); this.tabs.clear(); diff --git a/ts/tagsAnalysis.ts b/ts/tagsAnalysis.ts index a8d8185..139e981 100644 --- a/ts/tagsAnalysis.ts +++ b/ts/tagsAnalysis.ts @@ -87,8 +87,8 @@ class TagAnalysis { return; } let selectedRows: HTMLCollectionOf = document.getElementsByClassName('selected'); - for (let i = 0; i < selectedRows.length; i++) { - selectedRows[i].classList.remove('selected'); + for (let row of selectedRows) { + row.classList.remove('selected'); } tr.classList.add('selected'); } diff --git a/ts/termSearch.ts b/ts/termSearch.ts index 914658c..a3cc98e 100644 --- a/ts/termSearch.ts +++ b/ts/termSearch.ts @@ -46,7 +46,7 @@ class TermSearch { }); (document.getElementById('similarity') as HTMLSelectElement).value = '70'; (document.getElementById('searchText') as HTMLInputElement).focus(); - document.getElementById('languagesSelect').addEventListener('change', (ev: Event) => { + document.getElementById('languagesSelect').addEventListener('change', () => { let code: string = (document.getElementById('languagesSelect') as HTMLSelectElement).value; if (this.isBiDi(code)) { (document.getElementById('searchText') as HTMLInputElement).dir = 'rtl'; @@ -58,8 +58,7 @@ class TermSearch { setLanguages(arg: any): void { let array = arg.languages; let languageOptions = ''; - for (let i = 0; i < array.length; i++) { - let lang = array[i]; + for (let lang of array) { languageOptions = languageOptions + ''; } document.getElementById('languagesSelect').innerHTML = languageOptions; diff --git a/ts/translation.ts b/ts/translation.ts index 1ba4f7b..dcd0fa7 100644 --- a/ts/translation.ts +++ b/ts/translation.ts @@ -66,12 +66,12 @@ class TranslationView { srcLang: string; tgtLang: string; tbody: HTMLTableSectionElement; - numberTh: HTMLTableHeaderCellElement; - sourceTh: HTMLTableHeaderCellElement; - translateTh: HTMLTableHeaderCellElement; - matchTh: HTMLTableHeaderCellElement; - finalTh: HTMLTableHeaderCellElement; - targetTh: HTMLTableHeaderCellElement; + numberTh: HTMLTableCellElement; + sourceTh: HTMLTableCellElement; + translateTh: HTMLTableCellElement; + matchTh: HTMLTableCellElement; + finalTh: HTMLTableCellElement; + targetTh: HTMLTableCellElement; zoom: number = 1.0;