diff --git a/package.json b/package.json index 28cac72a..1f6a0c04 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ "build": "tsc && copyfiles static/webui/** build", "lint": "eslint --ext .ts .", "lint:fix": "eslint --fix --ext .ts .", - "prettier": "prettier --write ." + "prettier": "prettier --write .", + "update-translations": "cd scripts && node update-translations.js" }, "license": "GNU", "dependencies": { diff --git a/scripts/update-translations.js b/scripts/update-translations.js new file mode 100644 index 00000000..c26deb7f --- /dev/null +++ b/scripts/update-translations.js @@ -0,0 +1,46 @@ +// Based on http://209.141.38.3/OpenWF/Translations/src/branch/main/update.php +// Converted via ChatGPT-4o + +const fs = require('fs'); + +function extractStrings(content) { + const regex = /([a-zA-Z_]+): `([^`]*)`,/g; + let matches; + const strings = {}; + while ((matches = regex.exec(content)) !== null) { + strings[matches[1]] = matches[2]; + } + return strings; +} + +const source = fs.readFileSync("../static/webui/translations/en.js", "utf8"); +const sourceStrings = extractStrings(source); +const sourceLines = source.split("\n"); + +fs.readdirSync("../static/webui/translations").forEach(file => { + if (fs.lstatSync(`../static/webui/translations/${file}`).isFile() && file !== "en.js") { + const content = fs.readFileSync(`../static/webui/translations/${file}`, "utf8"); + const targetStrings = extractStrings(content); + const contentLines = content.split("\n"); + + const fileHandle = fs.openSync(`../static/webui/translations/${file}`, "w"); + fs.writeSync(fileHandle, contentLines[0] + "\n"); + + sourceLines.forEach(line => { + const strings = extractStrings(line); + if (Object.keys(strings).length > 0) { + Object.entries(strings).forEach(([key, value]) => { + if (targetStrings.hasOwnProperty(key)) { + fs.writeSync(fileHandle, `\t${key}: \`${targetStrings[key]}\`,\n`); + } else { + fs.writeSync(fileHandle, `\t${key}: \`[UNTRANSLATED] ${value}\`,\n`); + } + }); + } else { + fs.writeSync(fileHandle, line + "\n"); + } + }); + + fs.closeSync(fileHandle); + } +}); diff --git a/src/routes/webui.ts b/src/routes/webui.ts index 5ae72040..48f9f2fd 100644 --- a/src/routes/webui.ts +++ b/src/routes/webui.ts @@ -54,4 +54,9 @@ webuiRouter.get("/webui/riven-tool/RivenParser.js", (_req, res) => { res.sendFile(path.join(repoDir, "node_modules/warframe-riven-info/RivenParser.js")); }); +// Serve translations +webuiRouter.get("/translations/:file", (req, res) => { + res.sendFile(path.join(rootDir, `static/webui/translations/${req.params.file}`)); +}); + export { webuiRouter }; diff --git a/static/webui/index.html b/static/webui/index.html index 5448be04..dd87127a 100644 --- a/static/webui/index.html +++ b/static/webui/index.html @@ -34,13 +34,13 @@
Login using your OpenWF account credentials (same as in-game when connecting to this server).
+- Note: Changes made here will only be reflected in-game when the game re-downloads your - inventory. Visiting the navigation should be the easiest way to trigger that. -
+