discourse/test/javascripts/initializers/localization-test.js.es6

69 lines
1.5 KiB
Plaintext
Raw Normal View History

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