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

Some themes were doing `require("i18n").t()`, which was never recommended, but did work prior to f8483295. This commit restores that functionality with a deprecation notice.
This commit is contained in:
David Taylor 2023-07-11 16:15:30 +01:00 committed by GitHub
parent b45df10056
commit 5a30583174
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View File

@ -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) {

View File

@ -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");
});
});
});