Skip to content

Commit

Permalink
fix: get correct plural when n is in string
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuangya committed Sep 26, 2016
1 parent 7d7ac67 commit 4c39472
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
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

0 comments on commit 4c39472

Please sign in to comment.