Skip to content

Commit 1c04d3e

Browse files
committed
fix: get correct plural when n is in string
ref rubenv#313 fix rubenv#305
1 parent 7d7ac67 commit 1c04d3e

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/catalog.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ angular.module('gettext').factory('gettextCatalog', function (gettextPlurals, ge
258258
* @description Translate a plural string with the given context.
259259
*/
260260
getPlural: function (n, string, stringPlural, scope, context) {
261+
n = typeof n === 'number' ? n : parseInt(n, 10);
261262
var fallbackLanguage = gettextFallbackLanguage(this.currentLanguage);
262263
string = this.getStringFormFor(this.currentLanguage, string, n, context) ||
263264
this.getStringFormFor(fallbackLanguage, string, n, context) ||

test/unit/catalog.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,18 @@ describe("Catalog", function () {
6969
assert.equal(catalog.getPlural(1, "Bird", "Birds"), "Bird");
7070
});
7171

72+
it("Should return singular when n is 1 in string", function () {
73+
assert.equal(catalog.getPlural("1", "Bird", "Birds"), "Bird");
74+
});
75+
7276
it("Should return plural for unknown plural strings", function () {
7377
assert.equal(catalog.getPlural(2, "Bird", "Birds"), "Birds");
7478
});
7579

80+
it("Should return plural when n is more than 1 in string", function () {
81+
assert.equal(catalog.getPlural("2", "Bird", "Birds"), "Birds");
82+
});
83+
7684
it("Should return singular for singular strings", function () {
7785
catalog.setCurrentLanguage("nl");
7886
catalog.setStrings("nl", {

0 commit comments

Comments
 (0)