Skip to content

A platform for community discussion. Free, open, simple.

DEV: Add backwards-compatibility following i18n export change (#22540)

David Taylor5a305831747c
diff --git a/app/assets/javascripts/discourse/public/assets/scripts/module-shims.js b/app/assets/javascripts/discourse/public/assets/scripts/module-shims.js
index 442b9319973..e4630af4274 100644
--- a/app/assets/javascripts/discourse/public/assets/scripts/module-shims.js
+++ b/app/assets/javascripts/discourse/public/assets/scripts/module-shims.js
@@ -1,5 +1,17 @@
-define("I18n", ["exports"], function (exports) {
+define("I18n", ["exports", "discourse-common/lib/deprecated"], function (
+ exports,
+ deprecated
+) {
exports.default = I18n;
+ exports.t = function () {
+ deprecated.default(
+ "Importing t from I18n is deprecated. Use the default export instead.",
+ {
+ id: "discourse.i18n-t-import",
+ }
+ );
+ return I18n.t(...arguments);
+ };
});
define("htmlbars-inline-precompile", ["exports"], function (exports) {
diff --git a/app/assets/javascripts/discourse/tests/unit/lib/i18n-test.js b/app/assets/javascripts/discourse/tests/unit/lib/i18n-test.js
index 8deb904b152..4746fad0121 100644
--- a/app/assets/javascripts/discourse/tests/unit/lib/i18n-test.js
+++ b/app/assets/javascripts/discourse/tests/unit/lib/i18n-test.js
@@ -1,5 +1,6 @@
import { module, test } from "qunit";
import I18n from "I18n";
+import { withSilencedDeprecations } from "discourse-common/lib/deprecated";
module("Unit | Utility | i18n", function (hooks) {
hooks.beforeEach(function () {
@@ -288,4 +289,11 @@ module("Unit | Utility | i18n", function (hooks) {
"customtest"
);
});
+
+ test("legacy require support", function (assert) {
+ withSilencedDeprecations("discourse.i18n-t-import", () => {
+ const myI18n = require("I18n");
+ assert.strictEqual(myI18n.t("topic.reply.title"), "Répondre");
+ });
+ });
});