diff --git a/public/javascripts/helpers/i18n.js b/public/javascripts/helpers/i18n.js index 63ab758ef..8a16e2ecf 100644 --- a/public/javascripts/helpers/i18n.js +++ b/public/javascripts/helpers/i18n.js @@ -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 || {}); } }; diff --git a/spec/javascripts/app/views/post_view_spec.js b/spec/javascripts/app/views/post_view_spec.js index e4ff3b402..93f392411 100644 --- a/spec/javascripts/app/views/post_view_spec.js +++ b/spec/javascripts/app/views/post_view_spec.js @@ -7,7 +7,7 @@ describe("app.views.Post", function(){ Diaspora.I18n.loadLocale({stream : { reshares : { one : "<%= count %> reshare", - few : "<%= count %> reshares" + other : "<%= count %> reshares" } }}) diff --git a/spec/javascripts/widgets/i18n-spec.js b/spec/javascripts/widgets/i18n-spec.js index 28efb2f94..b25c8afa7 100644 --- a/spec/javascripts/widgets/i18n-spec.js +++ b/spec/javascripts/widgets/i18n-spec.js @@ -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"); - }); - }); }); }); });