2018-06-15 23:03:24 +08:00
|
|
|
import PreloadStore from "preload-store";
|
|
|
|
import LocalizationInitializer from "discourse/initializers/localization";
|
2017-02-24 18:31:21 +08:00
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
QUnit.module("initializer:localization", {
|
2017-02-24 18:31:21 +08:00
|
|
|
_locale: I18n.locale,
|
|
|
|
_translations: I18n.translations,
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
beforeEach() {
|
2017-02-24 18:31:21 +08:00
|
|
|
I18n.locale = "fr";
|
|
|
|
|
|
|
|
I18n.translations = {
|
2018-06-15 23:03:24 +08:00
|
|
|
fr: {
|
|
|
|
js: {
|
|
|
|
composer: {
|
|
|
|
reply: "Répondre"
|
2017-02-24 18:31:21 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2018-06-15 23:03:24 +08:00
|
|
|
en: {
|
|
|
|
js: {
|
|
|
|
topic: {
|
|
|
|
reply: {
|
|
|
|
help: "begin composing a reply to this topic"
|
2017-02-24 18:31:21 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
afterEach() {
|
2017-02-24 18:31:21 +08:00
|
|
|
I18n.locale = this._locale;
|
|
|
|
I18n.translations = this._translations;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-07-06 02:14:30 +08:00
|
|
|
QUnit.test("translation overrides", function(assert) {
|
2018-06-15 23:03:24 +08:00
|
|
|
PreloadStore.store("translationOverrides", {
|
|
|
|
"js.composer.reply": "WAT",
|
|
|
|
"js.topic.reply.help": "foobar"
|
|
|
|
});
|
2017-02-24 18:31:21 +08:00
|
|
|
LocalizationInitializer.initialize(this.registry);
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
assert.equal(
|
|
|
|
I18n.t("composer.reply"),
|
|
|
|
"WAT",
|
|
|
|
"overrides existing translation in current locale"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
I18n.t("topic.reply.help"),
|
|
|
|
"foobar",
|
|
|
|
"overrides translation in default locale"
|
|
|
|
);
|
2017-07-06 02:14:30 +08:00
|
|
|
});
|
2017-12-27 13:53:53 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
QUnit.test(
|
|
|
|
"skip translation override if parent node is not an object",
|
|
|
|
function(assert) {
|
|
|
|
PreloadStore.store("translationOverrides", {
|
|
|
|
"js.composer.reply": "WAT",
|
|
|
|
"js.composer.reply.help": "foobar"
|
|
|
|
});
|
|
|
|
LocalizationInitializer.initialize(this.registry);
|
2017-12-27 13:53:53 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
assert.equal(I18n.t("composer.reply.help"), "[fr.composer.reply.help]");
|
|
|
|
}
|
|
|
|
);
|