fix(common): make sure the plural category exists (#13169)

fixes #12379
This commit is contained in:
Victor Berchet
2016-12-01 13:26:24 -08:00
committed by Alex Rickabaugh
parent 12959f444c
commit 82c81cd0d2
2 changed files with 34 additions and 6 deletions

View File

@ -23,9 +23,23 @@ export abstract class NgLocalization { abstract getPluralCategory(value: any): s
*/
export function getPluralCategory(
value: number, cases: string[], ngLocalization: NgLocalization): string {
const nbCase = `=${value}`;
let key = `=${value}`;
return cases.indexOf(nbCase) > -1 ? nbCase : ngLocalization.getPluralCategory(value);
if (cases.indexOf(key) > -1) {
return key;
}
key = ngLocalization.getPluralCategory(value);
if (cases.indexOf(key) > -1) {
return key;
}
if (cases.indexOf('other') > -1) {
return 'other';
}
throw new Error(`No plural message found for value "${value}"`);
}
/**