mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: eradicate I18n fallback issues 💣
FIX: client's translation overrides were not working when the current locale was missing a key FIX: ExtraLocalesController.show was not properly handling multiple translations FIX: JsLocaleHelper#output_locale was not properly handling multiple translations FIX: ExtraLocalesController.show's spec which was randomly failing FIX: JsLocaleHelper#output_locale was muting cached translations hashes REFACTOR: move 'enableVerboseLocalization' to the 'localization' initializer REFACTOR: remove unused I18n.js methods (getFallbacks, localize, parseDate, toTime, strftime, toCurrency, toPercentage) REFACTOR: remove all I18n.pluralizationRules and instead use MessageFormat's pluralization rules TEST: add tests for localization initializer TEST: add tests for I18n.js
This commit is contained in:
43
test/javascripts/initializers/localization-test.js.es6
Normal file
43
test/javascripts/initializers/localization-test.js.es6
Normal file
@@ -0,0 +1,43 @@
|
||||
import PreloadStore from 'preload-store';
|
||||
import LocalizationInitializer from 'discourse/initializers/localization';
|
||||
|
||||
module("initializer:localization", {
|
||||
_locale: I18n.locale,
|
||||
_translations: I18n.translations,
|
||||
|
||||
setup() {
|
||||
I18n.locale = "fr";
|
||||
|
||||
I18n.translations = {
|
||||
"fr": {
|
||||
"js": {
|
||||
"composer": {
|
||||
"reply": "Répondre"
|
||||
}
|
||||
}
|
||||
},
|
||||
"en": {
|
||||
"js": {
|
||||
"topic": {
|
||||
"reply": {
|
||||
"help": "begin composing a reply to this topic"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
teardown() {
|
||||
I18n.locale = this._locale;
|
||||
I18n.translations = this._translations;
|
||||
}
|
||||
});
|
||||
|
||||
test("translation overrides", function() {
|
||||
PreloadStore.store('translationOverrides', {"js.composer.reply":"WAT","js.topic.reply.help":"foobar"});
|
||||
LocalizationInitializer.initialize(this.registry);
|
||||
|
||||
equal(I18n.t("composer.reply"), "WAT", "overrides existing translation in current locale");
|
||||
equal(I18n.t("topic.reply.help"), "foobar", "overrides translation in default locale");
|
||||
});
|
||||
55
test/javascripts/lib/i18n-test.js.es6
Normal file
55
test/javascripts/lib/i18n-test.js.es6
Normal file
@@ -0,0 +1,55 @@
|
||||
module("lib:i18n", {
|
||||
_locale: I18n.locale,
|
||||
_translations: I18n.translations,
|
||||
|
||||
setup() {
|
||||
I18n.locale = "fr";
|
||||
|
||||
I18n.translations = {
|
||||
"fr": {
|
||||
"js": {
|
||||
"hello": "Bonjour",
|
||||
"topic": {
|
||||
"reply": {
|
||||
"title": "Répondre",
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"en": {
|
||||
"js": {
|
||||
"hello": {
|
||||
"world": "Hello World!"
|
||||
},
|
||||
"topic": {
|
||||
"reply": {
|
||||
"help": "begin composing a reply to this topic"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
teardown() {
|
||||
I18n.locale = this._locale;
|
||||
I18n.translations = this._translations;
|
||||
}
|
||||
});
|
||||
|
||||
test("defaults", function() {
|
||||
equal(I18n.defaultLocale, "en", "it has English as default locale");
|
||||
ok(I18n.pluralizationRules["en"], "it has English pluralizer");
|
||||
});
|
||||
|
||||
test("translations", function() {
|
||||
equal(I18n.t("topic.reply.title"), "Répondre", "uses locale translations when they exist");
|
||||
equal(I18n.t("topic.reply.help"), "begin composing a reply to this topic", "fallbacks to English translations");
|
||||
equal(I18n.t("hello.world"), "Hello World!", "doesn't break if a key is overriden in a locale");
|
||||
});
|
||||
|
||||
test("extra translations", function() {
|
||||
I18n.extras = [{ "admin": { "title": "Discourse Admin" }}];
|
||||
|
||||
equal(I18n.t("admin.title"), "Discourse Admin", "it check extra translations when they exists");
|
||||
});
|
||||
@@ -41,7 +41,6 @@
|
||||
//
|
||||
//= require jquery.magnific-popup-min.js
|
||||
|
||||
window.TestPreloadStore = require('preload-store').default;
|
||||
window.inTestEnv = true;
|
||||
|
||||
// Stop the message bus so we don't get ajax calls
|
||||
|
||||
Reference in New Issue
Block a user