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:
parent
b45df10056
commit
5a30583174
|
@ -1,5 +1,17 @@
|
||||||
define("I18n", ["exports"], function (exports) {
|
define("I18n", ["exports", "discourse-common/lib/deprecated"], function (
|
||||||
|
exports,
|
||||||
|
deprecated
|
||||||
|
) {
|
||||||
exports.default = I18n;
|
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) {
|
define("htmlbars-inline-precompile", ["exports"], function (exports) {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { module, test } from "qunit";
|
import { module, test } from "qunit";
|
||||||
import I18n from "I18n";
|
import I18n from "I18n";
|
||||||
|
import { withSilencedDeprecations } from "discourse-common/lib/deprecated";
|
||||||
|
|
||||||
module("Unit | Utility | i18n", function (hooks) {
|
module("Unit | Utility | i18n", function (hooks) {
|
||||||
hooks.beforeEach(function () {
|
hooks.beforeEach(function () {
|
||||||
|
@ -288,4 +289,11 @@ module("Unit | Utility | i18n", function (hooks) {
|
||||||
"customtest"
|
"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");
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue