FIX: locale fallback with pluralized strings
This commit is contained in:
parent
54577db8a4
commit
5738253998
|
@ -151,7 +151,7 @@ I18n.translate = function(scope, options) {
|
||||||
try {
|
try {
|
||||||
if (typeof translation === "object") {
|
if (typeof translation === "object") {
|
||||||
if (typeof options.count === "number") {
|
if (typeof options.count === "number") {
|
||||||
return this.pluralize(options.count, scope, options);
|
return this.pluralize(translation, scope, options);
|
||||||
} else {
|
} else {
|
||||||
return translation;
|
return translation;
|
||||||
}
|
}
|
||||||
|
@ -258,16 +258,11 @@ I18n.findAndTranslateValidNode = function(keys, translation) {
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
I18n.pluralize = function(count, scope, options) {
|
I18n.pluralize = function(translation, scope, options) {
|
||||||
var translation;
|
|
||||||
|
|
||||||
try { translation = this.lookup(scope, options); } catch (error) {}
|
|
||||||
if (!translation) { return this.missingTranslation(scope); }
|
|
||||||
|
|
||||||
options = this.prepareOptions(options);
|
options = this.prepareOptions(options);
|
||||||
options.count = count.toString();
|
var count = options.count.toString();
|
||||||
|
|
||||||
var pluralizer = this.pluralizer(this.currentLocale());
|
var pluralizer = this.pluralizer(options.locale || this.currentLocale());
|
||||||
var key = pluralizer(Math.abs(count));
|
var key = pluralizer(Math.abs(count));
|
||||||
var keys = ((typeof key === "object") && (key instanceof Array)) ? key : [key];
|
var keys = ((typeof key === "object") && (key instanceof Array)) ? key : [key];
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,14 @@ module("lib:i18n", {
|
||||||
"reply": {
|
"reply": {
|
||||||
"title": "Répondre",
|
"title": "Répondre",
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"character_count": {
|
||||||
|
"zero": "{{count}} ZERO",
|
||||||
|
"one": "{{count}} ONE",
|
||||||
|
"two": "{{count}} TWO",
|
||||||
|
"few": "{{count}} FEW",
|
||||||
|
"many": "{{count}} MANY",
|
||||||
|
"other": "{{count}} OTHER"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -25,10 +33,24 @@ module("lib:i18n", {
|
||||||
"reply": {
|
"reply": {
|
||||||
"help": "begin composing a reply to this topic"
|
"help": "begin composing a reply to this topic"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"word_count": {
|
||||||
|
"one": "1 word",
|
||||||
|
"other": "{{count}} words"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// fake pluralization rules
|
||||||
|
I18n.pluralizationRules.fr = function(n) {
|
||||||
|
if (n == 0) return "zero";
|
||||||
|
if (n == 1) return "one";
|
||||||
|
if (n == 2) return "two";
|
||||||
|
if (n >= 3 && n <= 9) return "few";
|
||||||
|
if (n >= 10 && n <= 99) return "many";
|
||||||
|
return "other";
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
teardown() {
|
teardown() {
|
||||||
|
@ -53,3 +75,19 @@ test("extra translations", function() {
|
||||||
|
|
||||||
equal(I18n.t("admin.title"), "Discourse Admin", "it check extra translations when they exists");
|
equal(I18n.t("admin.title"), "Discourse Admin", "it check extra translations when they exists");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("pluralizations", function() {
|
||||||
|
equal(I18n.t("character_count", { count: 0 }), "0 ZERO");
|
||||||
|
equal(I18n.t("character_count", { count: 1 }), "1 ONE");
|
||||||
|
equal(I18n.t("character_count", { count: 2 }), "2 TWO");
|
||||||
|
equal(I18n.t("character_count", { count: 3 }), "3 FEW");
|
||||||
|
equal(I18n.t("character_count", { count: 10 }), "10 MANY");
|
||||||
|
equal(I18n.t("character_count", { count: 100 }), "100 OTHER");
|
||||||
|
|
||||||
|
equal(I18n.t("word_count", { count: 0 }), "0 words");
|
||||||
|
equal(I18n.t("word_count", { count: 1 }), "1 word");
|
||||||
|
equal(I18n.t("word_count", { count: 2 }), "2 words");
|
||||||
|
equal(I18n.t("word_count", { count: 3 }), "3 words");
|
||||||
|
equal(I18n.t("word_count", { count: 10 }), "10 words");
|
||||||
|
equal(I18n.t("word_count", { count: 100 }), "100 words");
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in New Issue