Skip to content
Open
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
23 changes: 16 additions & 7 deletions src/lang.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,13 @@
}
}

var pluralForm = this._getPluralForm(number);
var pluralForm = this._getPluralForm(number, locale);
//Check if pluralForm exists
if (messageParts.length > pluralForm) {
return messageParts[pluralForm];
}

return messageParts[pluralForm];
return messageParts[0];
};

/**
Expand All @@ -232,11 +236,12 @@
* @param key {string} The key of the message.
* @param count {number} The number of elements.
* @param replacements {object} The replacements to be done in the message.
* @param locale {string} The locale to use, if not passed use the default locale.
*
* @return {string} The translation message according to an integer value.
*/
Lang.prototype.transChoice = function(key, count, replacements) {
return this.choice(key, count, replacements);
Lang.prototype.transChoice = function(key, count, replacements, locale) {
return this.choice(key, count, replacements, locale);
};

/**
Expand Down Expand Up @@ -454,8 +459,9 @@
* @param {Number} count
* @return {Number}
*/
Lang.prototype._getPluralForm = function(count) {
switch (this.locale) {
Lang.prototype._getPluralForm = function(count, locale) {
locale = locale || this.getLocale();
switch (locale) {
case 'az':
case 'bo':
case 'dz':
Expand Down Expand Up @@ -645,7 +651,10 @@
: 5))));

default:
return 0;
//By default supports two plural forms
return (count == 1)
? 0
: 1;
}
};

Expand Down