fix(core): handle pluralize functions that expect a number (#36901)
Previously we were passing a string form of the value to pluralize to the `getLocalePluralCase()` function that is extracted from the locale data. But some locales have functions that rely upon this value being a number not a string. Now we convert the value to a number before passing it to the locale data function. Fixes #36888 PR Close #36901
This commit is contained in:

committed by
Alex Rickabaugh

parent
1c26f40cd4
commit
2ff4b357d7
@ -8,26 +8,15 @@
|
||||
|
||||
import {getLocalePluralCase} from './locale_data_api';
|
||||
|
||||
const pluralMapping = ['zero', 'one', 'two', 'few', 'many'];
|
||||
|
||||
/**
|
||||
* Returns the plural case based on the locale
|
||||
*/
|
||||
export function getPluralCase(value: any, locale: string): string {
|
||||
const plural = getLocalePluralCase(locale)(value);
|
||||
|
||||
switch (plural) {
|
||||
case 0:
|
||||
return 'zero';
|
||||
case 1:
|
||||
return 'one';
|
||||
case 2:
|
||||
return 'two';
|
||||
case 3:
|
||||
return 'few';
|
||||
case 4:
|
||||
return 'many';
|
||||
default:
|
||||
return 'other';
|
||||
}
|
||||
export function getPluralCase(value: string, locale: string): string {
|
||||
const plural = getLocalePluralCase(locale)(parseInt(value, 10));
|
||||
const result = pluralMapping[plural];
|
||||
return (result !== undefined) ? result : 'other';
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user