Skip to content

Commit 2259777

Browse files
committed
Fix: choice should use fallback logic for fallback locale.
This fixes #64. Again, thanks @nanaya.
1 parent 99b54b2 commit 2259777

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/lang.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@
221221
}
222222
}
223223

224-
var pluralForm = this._getPluralForm(number);
224+
locale = locale || this._getLocale(key);
225+
var pluralForm = this._getPluralForm(number, locale);
225226

226227
return messageParts[pluralForm];
227228
};
@@ -311,6 +312,22 @@
311312
return message;
312313
};
313314

315+
/**
316+
* Return the locale to be used between default and fallback.
317+
* @param {String} key
318+
* @return {String}
319+
*/
320+
Lang.prototype._getLocale = function(key) {
321+
key = this._parseKey(key, this.locale)
322+
if (this.messages[key.source]) {
323+
return this.locale;
324+
}
325+
if (this.messages[key.sourceFallback]) {
326+
return this.fallback;
327+
}
328+
return null;
329+
};
330+
314331
/**
315332
* Find a message in a translation tree using both dotted keys and regular ones
316333
*
@@ -452,10 +469,11 @@
452469
* Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
453470
*
454471
* @param {Number} count
472+
* @param {String} locale
455473
* @return {Number}
456474
*/
457-
Lang.prototype._getPluralForm = function(count) {
458-
switch (this.locale) {
475+
Lang.prototype._getPluralForm = function(count, locale) {
476+
switch (locale) {
459477
case 'az':
460478
case 'bo':
461479
case 'dz':

0 commit comments

Comments
 (0)