fallback to english pluralization rule if none is found

This commit is contained in:
Jonne Haß 2012-01-14 21:26:01 +01:00
parent c5654a43db
commit 5d0223601b
3 changed files with 8 additions and 42 deletions

View file

@ -9,7 +9,10 @@
loadLocale: function(locale, language) {
this.locale = locale;
this.language = language;
eval("this.pluralizationKey = "+this.t('pluralization_rule'));
rule = this.t('pluralization_rule');
if (rule === "")
rule = 'function (n) { return n == 1 ? "one" : "other" }';
eval("this.pluralizationKey = "+rule);
},
t: function(item, views) {
@ -26,11 +29,11 @@
return "";
}
}
if(views && typeof views.count !== "undefined") {
translatedMessage = translatedMessage[this.pluralizationKey(views.count)];
}
return _.template(translatedMessage, views || {});
}
};

View file

@ -7,7 +7,7 @@ describe("app.views.Post", function(){
Diaspora.I18n.loadLocale({stream : {
reshares : {
one : "<%= count %> reshare",
few : "<%= count %> reshares"
other : "<%= count %> reshares"
}
}})

View file

@ -6,8 +6,7 @@
describe("Diaspora", function() {
describe("widgets", function() {
describe("i18n", function() {
var locale = {
namespace: {
var locale = {namespace: {
message: "hey",
template: "<%= myVar %>",
otherNamespace: {
@ -56,42 +55,6 @@ describe("Diaspora", function() {
it("returns an empty string if the translation is not found", function() {
expect(Diaspora.I18n.t("missing.locale")).toEqual("");
});
describe("count", function() {
function translateWith(count) {
translation = Diaspora.I18n.t("namespace.otherNamespace.otherMessage", {
count: count
})
}
it("returns the 'zero' namespace if the count is zero", function() {
translateWith(0);
expect(translation).toEqual("none");
});
it("returns the 'one' namespace if the count is one", function() {
translateWith(1);
expect(translation).toEqual("just one");
});
it("returns the 'few' namespace if the count is 2 or 3", function() {
translateWith(2);
expect(translation).toEqual("just a few");
translateWith(3);
expect(translation).toEqual("just a few");
});
it("returns the 'many' namespace for any number greater than 3", function() {
translateWith(50);
expect(translation).toEqual("way too many");
});
});
});
});
});