From 6832b1596ef2342d887c42a78052954990b8e464 Mon Sep 17 00:00:00 2001
From: Kristjan ESPERANTO <35647502+KristjanESPERANTO@users.noreply.github.com>
Date: Sat, 11 Jul 2026 21:32:18 +0200
Subject: [PATCH] refactor: convert Translator to ES module
---
index.html | 1 -
js/main.js | 4 +-
js/module.js | 2 +
js/translator.js | 4 +-
tests/e2e/translations_spec.js | 114 ++++++++------------
tests/unit/classes/module_spec.js | 7 --
tests/unit/classes/translator_spec.js | 77 +++++++------
tests/unit/functions/cmp_versions_spec.js | 7 --
tests/utils/translation_test_environment.js | 43 ++++++++
9 files changed, 134 insertions(+), 125 deletions(-)
create mode 100644 tests/utils/translation_test_environment.js
diff --git a/index.html b/index.html
index d2d96d2951..dba2552069 100644
--- a/index.html
+++ b/index.html
@@ -49,7 +49,6 @@
-
diff --git a/js/main.js b/js/main.js
index 8cf9e20593..a13e11b41c 100644
--- a/js/main.js
+++ b/js/main.js
@@ -2,6 +2,8 @@
// eslint-disable-next-line import-x/extensions
import { loadModules } from "./loader.js";
+// eslint-disable-next-line import-x/extensions
+import { Translator } from "./translator.js";
let modules = [];
@@ -571,7 +573,7 @@ export const MM = {
Log.setLogLevel(config.logLevel);
- await globalThis.Translator.loadCoreTranslations(config.language);
+ await Translator.loadCoreTranslations(config.language);
await loadModules();
},
diff --git a/js/module.js b/js/module.js
index 756e0c771c..e853a38659 100644
--- a/js/module.js
+++ b/js/module.js
@@ -4,6 +4,8 @@
import { loadFileForModule } from "./loader.js";
// eslint-disable-next-line import-x/extensions
import { MMSocket } from "./socketclient.js";
+// eslint-disable-next-line import-x/extensions
+import { Translator } from "./translator.js";
/*
* Module Blueprint.
diff --git a/js/translator.js b/js/translator.js
index 05338e1ef4..38d3787bdc 100644
--- a/js/translator.js
+++ b/js/translator.js
@@ -1,6 +1,6 @@
/* global translations */
-const Translator = (function () {
+export const Translator = (function () {
/**
* Load a JSON file via fetch.
@@ -125,5 +125,3 @@ const Translator = (function () {
}
};
}());
-
-window.Translator = Translator;
diff --git a/tests/e2e/translations_spec.js b/tests/e2e/translations_spec.js
index ee275ae7fa..93d9a477b6 100644
--- a/tests/e2e/translations_spec.js
+++ b/tests/e2e/translations_spec.js
@@ -2,27 +2,23 @@ const fs = require("node:fs");
const path = require("node:path");
const { pathToFileURL } = require("node:url");
const helmet = require("helmet");
-const { JSDOM } = require("jsdom");
const express = require("express");
const translations = require("../../translations/translations");
+const {
+ setupTranslationTestEnvironment,
+ TRANSLATOR_MODULE_URL,
+ resetTranslatorState
+} = require("../utils/translation_test_environment");
/**
- * Helper function to create a fresh Translator instance with DOM environment.
- * @returns {object} Object containing window and Translator
+ * Create a fresh Translator state for each test.
+ * @returns {Promise