2017-06-14 13:57:58 -04:00
|
|
|
QUnit.module("lib:i18n", {
|
2017-02-24 05:31:21 -05:00
|
|
|
_locale: I18n.locale,
|
|
|
|
_translations: I18n.translations,
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
beforeEach() {
|
2017-02-24 05:31:21 -05:00
|
|
|
I18n.locale = "fr";
|
|
|
|
|
|
|
|
I18n.translations = {
|
|
|
|
"fr": {
|
|
|
|
"js": {
|
|
|
|
"hello": "Bonjour",
|
|
|
|
"topic": {
|
|
|
|
"reply": {
|
|
|
|
"title": "Répondre",
|
|
|
|
}
|
2017-02-28 04:02:29 -05:00
|
|
|
},
|
|
|
|
"character_count": {
|
|
|
|
"zero": "{{count}} ZERO",
|
|
|
|
"one": "{{count}} ONE",
|
|
|
|
"two": "{{count}} TWO",
|
|
|
|
"few": "{{count}} FEW",
|
|
|
|
"many": "{{count}} MANY",
|
|
|
|
"other": "{{count}} OTHER"
|
2017-02-24 05:31:21 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"en": {
|
|
|
|
"js": {
|
|
|
|
"hello": {
|
2017-03-01 05:30:44 -05:00
|
|
|
"world": "Hello World!",
|
|
|
|
"universe": ""
|
2017-02-24 05:31:21 -05:00
|
|
|
},
|
|
|
|
"topic": {
|
|
|
|
"reply": {
|
|
|
|
"help": "begin composing a reply to this topic"
|
|
|
|
}
|
2017-02-28 04:02:29 -05:00
|
|
|
},
|
|
|
|
"word_count": {
|
|
|
|
"one": "1 word",
|
|
|
|
"other": "{{count}} words"
|
2017-02-24 05:31:21 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2017-02-28 04:02:29 -05:00
|
|
|
|
|
|
|
// fake pluralization rules
|
|
|
|
I18n.pluralizationRules.fr = function(n) {
|
2017-02-28 04:33:16 -05:00
|
|
|
if (n === 0) return "zero";
|
|
|
|
if (n === 1) return "one";
|
|
|
|
if (n === 2) return "two";
|
2017-02-28 04:02:29 -05:00
|
|
|
if (n >= 3 && n <= 9) return "few";
|
|
|
|
if (n >= 10 && n <= 99) return "many";
|
|
|
|
return "other";
|
2017-02-28 04:33:16 -05:00
|
|
|
};
|
2017-02-24 05:31:21 -05:00
|
|
|
},
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
afterEach() {
|
2017-02-24 05:31:21 -05:00
|
|
|
I18n.locale = this._locale;
|
|
|
|
I18n.translations = this._translations;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
QUnit.test("defaults", assert => {
|
|
|
|
assert.equal(I18n.defaultLocale, "en", "it has English as default locale");
|
|
|
|
assert.ok(I18n.pluralizationRules["en"], "it has English pluralizer");
|
2017-02-24 05:31:21 -05:00
|
|
|
});
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
QUnit.test("translations", assert => {
|
|
|
|
assert.equal(I18n.t("topic.reply.title"), "Répondre", "uses locale translations when they exist");
|
|
|
|
assert.equal(I18n.t("topic.reply.help"), "begin composing a reply to this topic", "fallbacks to English translations");
|
|
|
|
assert.equal(I18n.t("hello.world"), "Hello World!", "doesn't break if a key is overriden in a locale");
|
|
|
|
assert.equal(I18n.t("hello.universe"), "", "allows empty strings");
|
2017-02-24 05:31:21 -05:00
|
|
|
});
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
QUnit.test("extra translations", assert => {
|
2017-02-24 05:31:21 -05:00
|
|
|
I18n.extras = [{ "admin": { "title": "Discourse Admin" }}];
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
assert.equal(I18n.t("admin.title"), "Discourse Admin", "it check extra translations when they exists");
|
2017-02-24 05:31:21 -05:00
|
|
|
});
|
2017-02-28 04:02:29 -05:00
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
QUnit.test("pluralizations", assert => {
|
|
|
|
assert.equal(I18n.t("character_count", { count: 0 }), "0 ZERO");
|
|
|
|
assert.equal(I18n.t("character_count", { count: 1 }), "1 ONE");
|
|
|
|
assert.equal(I18n.t("character_count", { count: 2 }), "2 TWO");
|
|
|
|
assert.equal(I18n.t("character_count", { count: 3 }), "3 FEW");
|
|
|
|
assert.equal(I18n.t("character_count", { count: 10 }), "10 MANY");
|
|
|
|
assert.equal(I18n.t("character_count", { count: 100 }), "100 OTHER");
|
2017-02-28 04:02:29 -05:00
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
assert.equal(I18n.t("word_count", { count: 0 }), "0 words");
|
|
|
|
assert.equal(I18n.t("word_count", { count: 1 }), "1 word");
|
|
|
|
assert.equal(I18n.t("word_count", { count: 2 }), "2 words");
|
|
|
|
assert.equal(I18n.t("word_count", { count: 3 }), "3 words");
|
|
|
|
assert.equal(I18n.t("word_count", { count: 10 }), "10 words");
|
|
|
|
assert.equal(I18n.t("word_count", { count: 100 }), "100 words");
|
|
|
|
});
|