Skip to content

Commit

Permalink
Fix: choice should use fallback logic for fallback locale.
Browse files Browse the repository at this point in the history
This fixes #64. Again, thanks @nanaya.
  • Loading branch information
rmariuzzo committed Dec 22, 2017
1 parent 99b54b2 commit 2259777
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/lang.js
Expand Up @@ -221,7 +221,8 @@
}
}

var pluralForm = this._getPluralForm(number);
locale = locale || this._getLocale(key);
var pluralForm = this._getPluralForm(number, locale);

return messageParts[pluralForm];
};
Expand Down Expand Up @@ -311,6 +312,22 @@
return message;
};

/**
* Return the locale to be used between default and fallback.
* @param {String} key
* @return {String}
*/
Lang.prototype._getLocale = function(key) {
key = this._parseKey(key, this.locale)
if (this.messages[key.source]) {
return this.locale;
}
if (this.messages[key.sourceFallback]) {
return this.fallback;
}
return null;
};

/**
* Find a message in a translation tree using both dotted keys and regular ones
*
Expand Down Expand Up @@ -452,10 +469,11 @@
* Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
*
* @param {Number} count
* @param {String} locale
* @return {Number}
*/
Lang.prototype._getPluralForm = function(count) {
switch (this.locale) {
Lang.prototype._getPluralForm = function(count, locale) {
switch (locale) {
case 'az':
case 'bo':
case 'dz':
Expand Down

0 comments on commit 2259777

Please sign in to comment.