angular/packages/core/src/i18n/localization.ts
Pete Bacon Darwin e5317d5eaf 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
2020-05-05 11:59:05 -07:00

32 lines
928 B
TypeScript

/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
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: string, locale: string): string {
const plural = getLocalePluralCase(locale)(parseInt(value, 10));
const result = pluralMapping[plural];
return (result !== undefined) ? result : 'other';
}
/**
* The locale id that the application is using by default (for translations and ICU expressions).
*/
export const DEFAULT_LOCALE_ID = 'en-US';
/**
* USD currency code that the application uses by default for CurrencyPipe when no
* DEFAULT_CURRENCY_CODE is provided.
*/
export const USD_CURRENCY_CODE = 'USD';