diff --git a/src/catalog.js b/src/catalog.js index fbc3688..a3b854b 100644 --- a/src/catalog.js +++ b/src/catalog.js @@ -258,6 +258,7 @@ angular.module('gettext').factory('gettextCatalog', function (gettextPlurals, ge * @description Translate a plural string with the given context. */ getPlural: function (n, string, stringPlural, scope, context) { + n = typeof n === 'number' ? n : parseInt(n, 10); var fallbackLanguage = gettextFallbackLanguage(this.currentLanguage); string = this.getStringFormFor(this.currentLanguage, string, n, context) || this.getStringFormFor(fallbackLanguage, string, n, context) || diff --git a/test/unit/catalog.js b/test/unit/catalog.js index d65947c..7d73f48 100644 --- a/test/unit/catalog.js +++ b/test/unit/catalog.js @@ -69,10 +69,18 @@ describe("Catalog", function () { assert.equal(catalog.getPlural(1, "Bird", "Birds"), "Bird"); }); + it("Should return singular when n is 1 in string", function () { + assert.equal(catalog.getPlural("1", "Bird", "Birds"), "Bird"); + }); + it("Should return plural for unknown plural strings", function () { assert.equal(catalog.getPlural(2, "Bird", "Birds"), "Birds"); }); + it("Should return plural when n is more than 1 in string", function () { + assert.equal(catalog.getPlural("2", "Bird", "Birds"), "Birds"); + }); + it("Should return singular for singular strings", function () { catalog.setCurrentLanguage("nl"); catalog.setStrings("nl", {