Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) ||
Expand Down
8 changes: 8 additions & 0 deletions test/unit/catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down