This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/tests/unit/localization-test.js
Robin Ward 71d37953d5 REFACTOR: Import QUnit and related helpers rather than globals
We used many global functions to handle tests when they should be
imported like other libraries in our application. This also gets us
closer to the way Ember CLI prefers our tests to be laid out.
2020-10-07 11:50:49 -04:00

68 lines
1.5 KiB
JavaScript

import { test, module } from "qunit";
import I18n from "I18n";
import LocalizationInitializer from "discourse/initializers/localization";
module("initializer:localization", {
_locale: I18n.locale,
_translations: I18n.translations,
_overrides: I18n._overrides,
beforeEach() {
I18n.locale = "fr";
I18n.translations = {
fr: {
js: {
composer: {
reply: "Répondre",
},
},
},
en: {
js: {
topic: {
reply: {
help: "begin composing a reply to this topic",
},
},
},
},
};
},
afterEach() {
I18n.locale = this._locale;
I18n.translations = this._translations;
I18n._overrides = this._overrides;
},
});
test("translation overrides", function (assert) {
I18n._overrides = {
"js.composer.reply": "WAT",
"js.topic.reply.help": "foobar",
};
LocalizationInitializer.initialize(this.registry);
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"
);
});
test("skip translation override if parent node is not an object", function (assert) {
I18n._overrides = {
"js.composer.reply": "WAT",
"js.composer.reply.help": "foobar",
};
LocalizationInitializer.initialize(this.registry);
assert.equal(I18n.t("composer.reply.help"), "[fr.composer.reply.help]");
});